Create a PR to update outdated libraries by script

Updating outdated libraries is important. Longtime outdated libraries probably lead difficult updating libraries. Sometimes they have breaking changes. We can reduce the risk updating libraries frequent and keep them small size.

Meanwhile, it’s difficult to catch up with ALL outdated libraries and updating them frequently. Since our works aren’t only updating them.

Get outdated libraries by anticuado

I’ve created https://github.com/KazuCocoa/anticuado to help get outdated libraries. Using the library, you can get outdated libraries as JSON format. Currently, the library supports the below.

  • Java
    • Gradle
  • iOS
    • CocoaPods
    • Carthage
  • Ruby
    • Bundler
  • Elixir
    • Hex
  • JavaScript
    • npm
    • yarn

How to use it

For example, you can run it against cocoapods.

require "anticuado"

cocoadpos = ::Anticuado::IOS::CocoaPods.new "path/to/project"
outdated = cocoadpos.outdated 
cocoadpos.format outdated

The output is the below.

[
  {
    library_name: "AFNetworking",
    current_version: "2.5.0",
    available_version: "3.1.0",
    latest_version: "3.1.0"
  },
  {
    library_name: "OHHTTPStubs",
    current_version: "4.1.0",
    available_version: "5.0.0",
    latest_version: "5.0.0"
  }
]

You can run it on CI services like Jenkins and send them to your slack channels.

Create a new PR automatically

Lately, I’ve added a feature to create a PR which include updating outdated libraries. The below is an example of cocoapods. The target repository is https://github.com/KazuCocoa/test.example. The result is https://github.com/KazuCocoa/test.examples/pull/2


# clone and set default branch
project_name = "project/test.examples" # To avoid nested bundler
# https://github.com/KazuCocoa/test.examples
g = ::Anticuado::GitHub.new "KazuCocoa/test.examples", enterprise: false
g.clone_or_open_to project_name
# Libraries I'd like to update
update_libraries_list = ['EarlGrey', 'Firebase/Core']
bundler = ::Anticuado::IOS::CocoaPods.new project_name
bundler.update_lock update_libraries_list
# create a PR
Dir.chdir(project_name) do
g.create_a_new_pull_request base_branch: 'master', head_branch: "update-#{Time.now.strftime '%Y%m%d-%H%M%S'}", update_libraries: update_libraries_list
end

view raw

2018-03-21.rb

hosted with ❤ by GitHub

If you have CI environment, automated tests should run after creating the PR. If they are green, you probably can merge it to master branch.

As a result, you can reduce the work to update outdated libraries by yourselves.

conclusion

The update logic is not complicated, but the tasks drain our time. This kind of work will improve your development environment step by step, I believe.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.