Like many iOS projects, yours probably also has external code dependencies. There’s a number of options how to manage them. You can do it manually by including other projects into your workspace or automate the whole process with tools such as Cocoapods, the newer Carthage or the little known peru, which functionally sits somewhere between manually managing dependencies and Carthage.
Whichever way you go, you should always integrate against known versions of these libraries to ensure that builds are reproducible. You’ll probably want to stay up to date with newer releases to receive security and bug fixes or performance improvements but at the same time not spend too much effort on manually updating them and verifying that there aren’t any bugs. This is were a nightly Canary Build comes into play that automatically checks for any updated libraries, creates a build, and runs your tests. A successful build indicates that it’s safe for you to update.
I’ll focus on Cocoapods here, since that’s the one we use at work and also has a nice option to check for new versions of pods. In its simplest form a
Podfile looks like this:
No version information whatsoever. But running
pod install will also generate a
Podfile.lock (which you should always check in to your repository). In the past I’ve shied away from doing this or the loosely versioned way of defining a dependency with e.g.
pod 'AFNetworking', '~> 2' because I wanted to be able to see which version of a library is included at a glance.
So in my case, the
Podfile might look something like this:
1 2 3 4 5 6 7 8 9 10 11 12
Cocoapods comes with the very handy
outdated command to find out about any new versions:
1 2 3 4 5 6 7 8 9 10 11
And then I’d usually go in by hand, update the
install and build the project. Obviously not the best use of anyone’s time. So this is where the Canary Build comes into play. As part of a Jenkins build script (I like ruby) you could do something like the following to automatically update a strictly versioned
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
A little bit of regex magic to extract the pod name and new version into a hash which we can match against the
Podfile and update if needed. Then the script would go off and run
pod update, build and run tests and maybe even upload to HockeyApp or TestFlight and send out an email with which pods it updated.
But of course once you start automating this, there is no need to actually version the pods anymore since you’ll have the generated
Podfile.lock and/or let the script inform you about any pods it did update. In such a case it’s enough to simply:
1 2 3 4 5 6 7 8 9
A similar approach should also be possible using Carthage if you’re willing to go without fixed versions since it will generate a
Cartfile.resolved with a fixed version used for the build.
We have several Jenkins jobs running already for different branches and pre-release versions. Adding a nightly Canary Build is a logical next step and I’d urge anyone to give it a try. The effort to set it up is fairly low but it does free up a lot of time in the long run and should also help with the overall stability of your apps. I’d love to hear about your ideas or experiences with such a process. Get in touch on Twitter.