How to setup Travis CI for a rails application
1. Register
First you will need to sign up for Travis:
Then choose the Github project you want to work on by flicking the repository switch on the profile page.
2. Add travis.yml file
Add this line to your Gemfile:
gem 'travis'
Then run:
bundle install
You can either create the travis.yml file or run the below command and it will create it for you:
travis init
3. Add to your travis file
These are commands to add to your travis.yml file:
Language:
language: ruby
Language version:
rvm:
— 2.5.0
If the ruby version isn’t specified here, travis will look to your .ruby-version if there is one.
Then add the commands necessary to run the tests:
script:
— bundle install — jobs=3 — retry=3
— bundle exec rake db:create
— bundle exec rake db:migrate
— bundle exec rspec
On line 2 I ran bundle install to install all the gems in the Gemfile. For my application I had a database connected so to get it up and running on travis I told it to create the database and then migrate ( line 3 & 4). Finally to run the tests on travis you will need the command on line 5.
You may need extra commands to get your project working. For a detailed list, see the travis Ruby guide:
https://docs.travis-ci.com/user/languages/ruby/#What-This-Guide-Covers
4. Check your travis file is valid and get going
You can check if your travis.yml is valid by installing the travis-lint gem:
gem install travis-lint
And then run the command:
travis lint
Once you have a valid travis, you can push your changes to Github and travis will start running its checks.
You can watch it do so by going on the Travis website and signing in or simply run:
travis open