package.json? Forgetting to maintain a changelog? Failing to publish to npm? If so I’m here to tell you that all of that can be automated for free on an open source project. Before we dive into the nitty gritty here are the pieces to this beautiful puzzle:
Setup Travis CI
Now that we know what we will be working with it is time to dive in. I am going to assume you already have a Github repository and are ready to automate your builds. The first step is to visit Travis CI and click the Sign in with Github button. Make sure to grant Travis the permissions requested for your Github account.
Once you are logged into Travis you can activate builds for your repository by visiting a link in the following format: https://travis-ci.org/<username>/<repository>. Simply replace <username> with your Github username or organization and replace <repository> with the name of your Github repository. Once you visit this page there should be an Activate repository button, go ahead and press it. Next we’ll need to add a configuration file for Travis to the repostiry, so it knows what to do. In the root directory of your repository add the following file:
Note: Apply these changes in a branch/fork in which you do your development. This assumes a workflow where your published/upstream branch is separate from your development branch. If you have an organization that you make pull requests to then this is probably as simple as making the changes in your fork. If you are not working with an organization/fork you probably want a development branch as well as the master branch.
language: node_js node_js: - stable install: - npm install script: - npm test
The language tells Travis our project is using Node.js, and the stable tells it we want to use the latest version of Node, which as of writing this article is Node 7. The install step tells Travis to run npm install to install necessary dependencies and the script tells Travis to run npm test for the tests. If npm test fails then the Travis build will fail. This script should be wired up to run whatever tests you have in your project. For example if your project is an Ember application you’d probaby have npm test set to run ember test or ember try. At this stage if you were to make a pull request against the master branch of your repository you’d see a pending check in the Github UI as well as a CI build in the Travis UI.
This article is not complete, stay tuned for the rest of it.