Setting up Travis

Its always fun to learn and implement new technologies. Travis-CI a FOSS for continuous integration and deployment, is one such tool I always wanted to learn. Finally, today, I did get some motivation to get started with Travis to auto build and deploy a paper I am currently writing in LaTex.

The code is hosted on Github within a private repository, Travis pro provides access to build, test and deploy from private repositories.

Installing Travis

Run the following commands to install and setup Travis-cli which will help auto-generation of configuration file .travis.yml. This file can also be created without the tool, auto generation always makes life easy.

        curl -sSL https://get.rvm.io | bash -s stable --ruby
        source /$HOME/.rvm/scripts/rvm
        gem install travis

Setup Github and Travis

Goto settings on the Github repository, Choose webhooks and services > Add service and select Travis-CI. This will allow travis to start building when a commit has been pushed.

Also, make sure the repository is enabled within the Travis webpage. on the travis home page, you can toggle required repositories for building.

Generate and configure .travis.yml

.travis.yml is a configuration file that defines the build process for your repository. Travis documentation provides an in-depth explanation for the various build configurations. Here I will stick to my own requirement.

Go to the cloned repository, use the command:

        travis setup releases

Follow the steps to generate the .travis.yml file.

Update the .travis.yml file based on need, here is the file I use.

        before_install:
        - "sudo apt-get update && sudo apt-get install -y --no-install-recommends  dvipng latexmk texlive texlive-base texlive-full"
        script:
        - latexmk -pdf myTexFile.tex
        before_deploy:
        - git fetch --tags
        deploy:
          provider: releases
          api_key:[Your Key]
          file: myTexFile.pdf
          skip_cleanup: true
         on:
            repo: gitUsername/repoName
            tags: true
            all_branches: true

The main updates here are, the before_install scripts, we first install all dependencies before actually compiling the program. skip_cleanup tells Travis not to stash all changes before the code is deployed.

This configuration is done for all tagged commits on Github. For various issues, the field all_branches needs to be defined and also git fetch --tags makes sure it has all valid tags before starting the deploy phase.

Testing

It must now be possible to automatically generate builds, to generate a build make sure to tag your commit, using:

      git commit -a -m "Message"
      git tag tagName
      git push origin master --tags

This should now trigger a build on the Travis server. Builds can be monitored from the user’s homepage. If build and deployment was a success, you should see the files under releases tab on the repository.

comments powered by Disqus