Advanced uses of Travis CI with Nim

There have been a few guides describing the use of Circle CI, originating from here. But in my opinion Travis CI is a superior service, because it has more options and is more reliable.

Basic setup

Let's start with the minimal Travis configuration that allows you to test Nim projects.

wzxhzdk:0


Look at this guide to get an idea about how to set up the actual tests.

You may think that the folder name nim-master is redundant, but you'll see later why I didn't call it just nim.

All this custom stuff is needed because Travis doesn't officially support Nim. And we need to pick some language. The choice of C language could be called arbitrary, but we do use C compilers here, so it's nice to make sure they're available.

Caching

Now, downloading, bootstrapping and recompiling everything every time is slow and wasteful. Let's add caching!

wzxhzdk:1

So, after successful builds, the directory nim-master will be stored in the cache, and we can reuse it in the next builds. This is especially important when testing using Nim's master branch which rarely changes.

Another change is how the directory is added to PATH. We avoid the stray colon if PATH is empty, which would mean that we also have an empty entry in PATH (current directory)

Multiple Nim versions

Our next step is testing the project under multiple different configurations.

Make sure you understand what the Build matrix is.

wzxhzdk:2

One more thing I packed into this example is 'build all branches except for gh-pages'. But that's the default behavior of Travis anyway.

See this configuration in action:

Different configurations per branch

Another thing you may want to do is maintain 2 branches of your project:

  • master, which is supposed to work with Nim master
  • devel, which is supposed to work with Nim devel

So let's get to action!

wzxhzdk:3

Another change here is the last two lines. They enable The Trusty beta Build Environment. I needed this because the default environment has a very outdated version of PCRE, and Nim's regular expression support relies on a newer one. Sadly, cache doesn't work in this "sudo" environment, so that's gone.

See this configuration in action:

Created
Comments powered by Disqus