Integrating Travis CI with your GitHub Project

Travis CI is a continuous integration service used to build and test projects hosted at GitHub. Every time a commit is made and pushed to the GitHub repository, Travis CI automatically detects it and tries to build the project and run tests. Upon completion of its build process it provides a report of all the jobs that have passed or failed. In this way one can check whether a commit has broke something and try to fix it before it becomes a problem.

Integrating Travis CI with your GitHub project can be done in 3 simple steps:

1. Visit your profile page on Travis CI website. If not signed in, you can sign in with GitHub. Then you will see a list of your repositories and flick the repository switch on for the repo you want to integrate with Travis.

2. Add .travis.yml file to your repository. This file will contain the details like language, versions of language to test on, command to install dependencies and test script. Lets consider a Python project and define .travis.yml for the project.

i. You have to first specify the language in the file:

language: python

ii. Add versions for the language to test on:

python:
  - "2.7"
  - "3.3"
  - "3.4"
  - "3.5"
  - "3.5-dev" # 3.5 development branch
  - "3.6"
  - "3.6-dev" # 3.6 development branch
  - "3.7-dev" # 3.7 development branch
  - "nightly" # currently points to 3.7-dev

If you don’t include the python key in your file then Travis will build the project for Python 2.7 by default.

iii. Add the command to install dependencies if any:

Travis CI uses isolated virtualenvs to install dependencies. To install Python dependencies use pip.

install:
  - pip install .
  - pip install -r requirements.txt

If you want to skip the installation step then you can specify it as:

install: true

iv. Specify the test script:

If you are using pytest to run the tests:

script: pytest

Or if you are using make test instead:

script: make test

Finally your .travis.yml file should look somewhat like the following:

language: python
python:
"2.7"
"3.3"
"3.4"
"3.5"
"3.5-dev" # 3.5 development branch
"3.6"
"3.6-dev" # 3.6 development branch
"3.7-dev" # 3.7 development branch
"nightly" # currently points to 3.7-dev
# command to install dependencies
install:
pip install .
pip install -r requirements.txt
# command to run tests
script: make test

view raw
.travis.yml
hosted with ❤ by GitHub

3. Commit your changes and trigger your first build with a git push. You can visit the dashboard and see all your builds for the project.

3 thoughts on “Integrating Travis CI with your GitHub Project

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s