Posted on November 29, 2014

Adding a Travis build status badge to your Github repo

My friend Xesus just recently discovered the beauty of functional programming and has been playing with SML, Ruby and Racket. Seeing as he’s happy with less social life and more programming skills, I suggested Project Euler, lest he becomes bored and starts going out and meeting people again. He took the bait, so to speak, and here it is, his solution to problem 1.

Well, that repository README file looks nice and all, and although his solution was written in a toy scripting dialect there is hope – he also wants to implement it in Racket. :-)

Still, there’s something that README file is not telling me, the potential person interested in his Project Euler solution – is that code really working? Are there tests? Are those tests passing?

This post is, instead of a conversation, a mini tutorial to adding a Travis badge to a github repo. To exemplify, I’ll be doing it for my Project Euler solutions, which were written in Java, a programming language.

So now let’s go and create a .travis.yml file in our repo. This file will contain the settings for the programming language your repo uses. Things like what SDK to use, what dependencies do you need to run a build, etc. You can read all about it in the Travis Documentation. For my Java Euler solutions let’s do the following:

    language: java
    jdk: oraclejdk8

Since, travis will by default run mvn tests for mavenized Java projects, that’s perfect for me since my Project Euler problems are actually test cases. However, you can completely customize you build process, including using shell scripts which can be useful for multi language projects.

Ok, so now that I have my .travis.yml file created, I push it and a few minutes afterwards I already see my build passing.

However, the repo’s page still doesn’t tell me the status of this build. Let’s change that then.

According to the documentation we can add those nice badges to our README.md by clicking the build passing badge in the build page and choosing markdown from the dropdown menu. In my case, I just add the following line to the top of my README.md:

    [![Build Status](https://travis-ci.org/decomputed/euler.svg?branch=master)](https://travis-ci.org/decomputed/euler)

And now, there’s a beautiful green badge showing that my solutions are passing the tests. :-)