Travis-CI for the Markua Parser project
It is very useful to write unit-tests for your project, but it is a bit annoying that you have to remember running it every time before you push out a new request. Especially if you'd like to run your tests on multiple versions of Perl and maybe with different values of certain environment variables.
Travis-CI is a cloud-based Continuous Integration system that will run your tests on every commit on as many versions of Perl as you like and with as many environment variables as you configure.
Not only that, but every time someone sends you a pull-request the tests will run on the PR as well, so both the contributor and you will know if the PR would break anything that worked before.
Not only that, but Travis-CI is free for Open Source projects on GitHub.
For simple cases it is quite easy to set up Travis-CI. It involves two steps:
- Tell Travis-CI to monitor your project
- Create the Travis Configuration file .travis.yml
Tell Travis-CI to monitor your project
Visit Travis-CI, log in with your GitHub account and let it sync the list of your GitHub repositories.
If you have already done this earlier, then for a new GitHub project you might need to manually ask Travis to sync the list.
For this visit your Profile and click on the Sync account. After a few seconds you'll be able to locate the entry of your project.
Look at the relevant switch which is currently off:
and turn it on:
Create the Travis Configuration file .travis.yml
For every language Travis supports there are instructions on how to set them up. So there are instructions for Perl-based projects on Travis.
Basically you need to create a file called .travis.yml in the root of your Git repository with the following content listing the versions of perl you'd like to be used by Travis:
language: perl perl: - "5.26" - "5.24" - "5.22" - "5.20"
The file is in YAML format.
$ git add $ git commit -m "add travis configuration file" $ git push
Once you push the file to GitHub it will trigger Travis-CI and that will start a build. Because we requested the build on 4 different versions of Perl, Travis will spun-off 4 virtual machines and run the builds and the tests in parallel.
Here are the Travis-CI build results for my first build of this project.
A screenshot of that page:
You will also receive an e-mail confirmation with the first successful build. Such as this one:
From now on every push to GitHub will trigger the build. If any one of the builds fail you'll get an e-mail notification so you don't have to do anything, just keep coding.
It is quite customary that Open Source developers will add a Travis badge to their project. On the results page on Travis you'll see a badge (it probably will say "build unknown"). If you click on it, you'll get a popup like this allowing you to select the appropriate code for the badge.
I've pasted the Markdown example into the README.md file of the project:
# Markua Parser [![Build Status](https://travis-ci.org/szabgab/perl5-markua-parser.svg?branch=master)](https://travis-ci.org/szabgab/perl5-markua-parser) [Markua](https://leanpub.com/markua/) is a Markdown-inspired format to write books. This module implements parsing (part of) the Markua specification.
$ git add . $ git commit -m "add Travis badge" $ git push
This push will trigger another build on Travis, but what is more interesting for us now is that of someone visits the GitHub page of the Perl 5 Markua Parser project then they will see the up-to-date status of the project on Travis: