Publishing to Github releases from Travis CI



If you’re developing a node.js package, you can publish it to npmjs. If you’re developing a .NET package, you can publish it to nuget. But what if you’re developing a standalone executable, where do you publish it?

I was faced with this dilemma when I wrote ruready. Even though ruready is written in go, it gets compiled into an executable and I want the users to have a way of getting it in that form. Of course, you can always get the source code and compile it yourself but ruready is designed to be standalone and to be deployed on a machine that doesn’t have go installed (such as the Alpine Linux docker image).

Github introduced recently the releases feature. It allows repositories to publish files, up to 2 GB in size (at the time of writing), as part of a versioned release. If your build produces binaries, you can store them for free, outside of the git repository, on Github. Then Github will advertise those release as part of the repository, will keep them sorted by date, and will allow your users to download the files. That’s exactly what I needed!

Travis CI allows you to build your project and then publish the build output to Github releases. When you push code to Github, Travis can pick it up, build it, and publish it.

To publish build artifacts to Github from Travis CI, do the following:

  1. Sign up for Travis CI. It’s free for public repositories.

  2. Authorize it to access your github account.

  3. In your Travis account page, enable the Travis build for that repository.

  4. In your repository’s root, create a file called .travis.yml with the following content, in addition to everything that your build needs:

     deploy2:
         provider: releases
         api_key:
             secure: <your key>
         file: 
             - file1
             - file2
             - ...
         skip_cleanup: true
         on:
             repo: <your repository path>
             tags: true
    

Let’s see what each property means:

If the example above is confusing, here’s the full file: https://github.com/victorhurdugaci/ruready/blob/master/.travis.yml. On every build with a tag, it uploads ruready (the executable) and a text file ruready.sha1 (the checksum for that release):

In addition to the two files, github also creates two archives with the source code.