During the refactoring work on the project I'm working for at Jumbo, went through many different changes and the first one was implementing a new networking layer. We decided to create an external library and make it open source: it was the perfect moment to try a new CI system. Long live Travis CI!
Table of Contents
Let's start with a little introduction: Travis CI is a continuous integration service used to build and test projects hosted on GitHub.
There are many alternatives around, but after trying few of them we decided to use Travis CI because it is very easy to configure and integrates perfectly with GitHub, where our library lives.
Having a CI system that automatically tests your code is - in my opinion - the very first step when creating an open source library: it will assure that every commit is validated and that all the tests written are passed (and if you want a quick list of benefit, I like this summary by Gitlab).
In order to start using it, there are 2 prerequisites:
- You must have a GitHub account
- Your repository must be a public repository on GitHub
Once you have satisfied them, it's time to start 😊.
Connect Travis CI and GitHub
The connection between the two services is pretty smooth:
- Go to Travis CI website
- Select the top right button "Sign in with GitHub"
- Accept the Authorization of Travis CI and authorize it once redirected to GitHub
- Go to your settings page and activate the repository you want to have under CI. Your page should look like the picture below.
That's it! Now your repository is connected with Travis CI, but we still need to configure it.
Configure Travis CI
The configuration of Travis CI consists in a single file that you need to add to your root folder, named
.travis.yml. This file will contain all the configurations needed for your project, but in order to run your projects tests quickly you can start with a minimal configuration.
In our case, this is all we need:
language: objective-c osx_image: xcode10 xcode_workspace: JNetworkingKit/JNetworkingKit.xcworkspace xcode_scheme: JNetworkingKit xcode_sdk: iphonesimulator12.0 xcode_destination: platform=iOS Simulator,OS=12.0,name=iPhone X
Let's have a quick look:
language: the language of your project (in case of Swift you have to still have to use
osx_image: the Xcode version to run your tests. Since we are still on Xcode 10.2.1,
xcode10is the configuration that works for us
xcode_workspace: the location of your project
xcode_scheme: the scheme to test
xcode_sdk: the SDK version
xcode_destination: the simulator information
From this moment on, every commit will trigger a build on Travis CI, running your unit tests:
That's all: starting to use a CI system is very easy (the entire process took less than 15 minutes for us) and will increase the quality of your projects without a lot of effort. More configurations are available on Travis CI to satisfy all your needs.
Bonus point: your readme page on GitHub can also show the build status from Travis CI. This is our code, but using your repository information will show the magic 👏🏻:
Enjoy your CI,
» Revision: 1