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.
.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:
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:
iv. Specify the test script:
If you are using
pytest to run the tests:
Or if you are using
make test instead:
script: make test
.travis.yml file should look somewhat like the following:
|– "3.5-dev" # 3.5 development branch|
|– "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|
|– pip install .|
|– pip install -r requirements.txt|
|# command to run tests|
|script: make test|
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.