Integrating Travis CI in your Github project
Travis CI is an open-source hosted, distributed, and continuous integration service used to build and test projects hosted at GitHub.
Continuous Integration (CI)
Continuous Integration is a process of running all unit tests on the latest code which is submitted to check if the newly added components have not broken any old functionality. It is very important from testing and deployment perspectives. It prevents the problems of after-deployment rollbacks. They are time-taking and reduce the reliability of products.
You can use [Jenkins](https://www.codementor.io/slavko/tutorials/setup-configure-jenkins-recommended-plugins-du107z6nr ''Setup & Configure Jenkins for Your Team") and many other continuous integration servers for this purpose but for using these, you will have to set them up on a server and maintain this server using your dedicated dev-ops engineer that is, if you have got one. If you can achieve this, they provide you with a lot of control and flexibility.
Why Travis CI
Let's say you don't want to hire a dedicated dev-ops engineer or are in no need to dedicate a server to CI but you want to use CI as it is very important for your product. Travis CI comes to your help here. You don't have to maintain your own server or set up travis anywhere. Just include a few files in your repository for Travis to read and you are done.
Travis has support for many languages and platforms. I use it for my Swift Cocoapod libraries, too.
In this tutorial, I am providing steps to integrate Travis CI into your public Github repository.
Steps to Integrate Ruby on Rails Github public repo with Travis CI.
- Enable Travis from your repository settings → Integration and services → services
- Go to Travis console from the link there. If you don’t have a Travis account, create one, and it will list all your repositories.
- Enable the repository you wish to integrate by flicking the switch next to it.
- Now, create a
.travis.ymlfile similar to this:
language: ruby rvm: - "2.1.3" env: - DB=postgresql script: - RAILS_ENV=test bundle exec rake db:create db:migrate --trace - bundle exec rspec test/ before_script: - cp config/database.travis.yml config/database.yml - mysql -e 'create database mydb_test' bundler_args: --binstubs=./bundler_stubs
- The file above file should be added to your repo's root directory that is, top level.
- Add a
default: &default adapter: postgresql test: <<: *default database: mydb_test username: travis encoding: utf8
Now push the changes and let it create the first build.
Now, every time you push changes to your repository's master branch (you can specify a different branch through settings in Travis repository settings), your unit tests will be automatically run and any failures will be mailed to your Github attached email account.