Skip to content
sarken edited this page Oct 19, 2016 · 9 revisions

Travis-CI is an OpenSource Continuous Integration platform. When it's hooked up, every time a pull request is submitted to the otwcode/otwarchive repository on GitHub, Travis-CI will grab a copy of the code changes, merge them into a master copy, and then run our test suite against that new copy of the code. It will run the tests again whenever a pull request is merged into master.

Results will be sent to the #otw-dev channel on freenode and the otw-coders-extra mailing list as detailed in the [How It Looks section](#How it looks). Additionally, project members with merge permissions will be able to see the build status near the merge button on each pull request.

You can also [set up Travis-CI to work with your copy of the otwarchive repo](#Travis-CI/GitHub Link Setup) so you can test your changes before submitting a pull request. It requires some setup, but it is well worth it -- Travis-CI runs our test suite much faster than most development environments.

Code setup

Last updated 13 July 2016.

Should all else be lost, you can use these steps in order to set up a fresh copy of otwarchive so that it integrates itself with Travis-CI. Changes to pre-existing files have been marked in bold.

  • Create the .travis.yml file in the root directory:
language: ruby
sudo: required
env:
  - TEST_GROUP="./script/check_syntax"
  - TEST_GROUP="rspec spec"
  - TEST_GROUP="cucumber -f progress -r features features/admins"
  - TEST_GROUP="cucumber -f progress -r features features/bookmarks"
  - TEST_GROUP="cucumber -f progress -r features features/collections"
  - TEST_GROUP="cucumber -f progress -r features features/comments_and_kudos"
  - TEST_GROUP="cucumber -f progress -r features features/gift_exchanges"
  - TEST_GROUP="cucumber -f progress -r features features/importing"
  - TEST_GROUP="cucumber -f progress -r features features/other_a"
  - TEST_GROUP="cucumber -f progress -r features features/other_b"
  - TEST_GROUP="cucumber -f progress -r features features/prompt_memes_a"
  - TEST_GROUP="cucumber -f progress -r features features/prompt_memes_b"
  - TEST_GROUP="cucumber -f progress -r features features/prompt_memes_c"
  - TEST_GROUP="cucumber -f progress -r features features/tags_and_wrangling"
  - TEST_GROUP="cucumber -f progress -r features features/users"
  - TEST_GROUP="cucumber -f progress -r features features/works"
rvm:
  - "2.1.9"
services:
  - elasticsearch
  - redis-server
  - memcached
script:
  - rm -f structure.sql
  - RAILS_ENV=test bundle exec rake db:create:all --trace
  - RAILS_ENV=test bundle exec rake db:schema:load --trace
  - RAILS_ENV=test bundle exec rake db:migrate --trace
  - travis_retry bundle exec $TEST_GROUP
before_script:
  - bash script/travis_configure.sh
  - bash script/travis_elasticsearch_upgrade.sh
notifications:
  email:
    recipients:
      - [email protected]
    on_success: change
    on_failure: always
  irc:
   channels:
     - "irc.freenode.org#otw-dev"
   on_success: change
   on_failure: change
  • Create the /config/database.travis.yml file:
  test:
    adapter: mysql2
    database: otwarchive_test
    username: root
    encoding: utf8
  • Create the /config/redis.travis.example file:
  redis_resque:
    test: localhost:6379
  redis_kudos:
    test: localhost:6379
  redis_general:
    test: localhost:6379
  redis_rollout:
    test: localhost:6379
  • Edit /config/initializers/gem-plugin_config/redis.rb as follows:
  require 'redis_test_setup'
  include RedisTestSetup
  
  if ENV['TRAVIS']
    rails_root = ENV['TRAVIS_BUILD_DIR']
    rails_env = 'test'
  else
    rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../../..'
    rails_env = ENV['RAILS_ENV'] || 'development'
  end
  
  unless ENV['TRAVIS']
    if rails_env == "test"
      # https://gist.github.com/441072
      start_redis!(rails_root, :cucumber)
    end
  end
  redis_config = YAML.load_file(rails_root + '/config/redis.yml')
  redis_host, redis_port = redis_config[rails_env].split(":")
  $redis = Redis.new(:host => redis_host, :port => redis_port)
  • Edit config/initializers/gem-plugin_config/resque.rb as follows:
  require 'resque'
  
  if ENV['TRAVIS']
    rails_root = ENV['TRAVIS_BUILD_DIR']
    rails_env = 'test'
  else
    rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../../..'
    rails_env = ENV['RAILS_ENV'] || 'development'
  end
  
  redis_config = YAML.load_file(rails_root + '/config/redis.yml')
  Resque.redis = redis_config[rails_env]
  
  # in-process performing of jobs (for testing) doesn't require a redis server
  Resque.inline = ENV['RAILS_ENV'] == "test"
  
  Resque.after_fork do
    Resque.redis.client.reconnect
  end

Travis-CI/GitHub link setup

  1. Log in to Travis-CI with GitHub
    1. In your browser, navigate to http://travis-ci.org
    2. Choose 'Sign in with GitHub' in the top right-hand corner of your screen
      • If you're not signed in to GitHub, you'll need to enter your GitHub credentials
  2. Get a list of your repositories
    1. Hover over your name in the upper right corner of the page and select 'Accounts', or go straight to your Travis-CI profile
    2. Choose 'Sync account' to grab a list of your repositories
  3. Turn on and set up Travis-CI for your otwarchive repository
    1. Use the switch next to YOUR_GITHUB_USERNAME/otwarchive to turn on Travis-CI
    2. Select the name of your repository to go to its page on GitHub, e.g. https://github.com/YOUR_GITHUB_USERNAME/otwarchive
    3. Go to your repository's settings page by choosing the the 'Settings' link/gear icon link or go directly to https://github.com/YOUR_GITHUB_USERNAME/otwarchive/settings on your repo's page
    4. Go to the 'Webhooks & services' section of your settings, i.e. https://github.com/YOUR_GITHUB_USERNAME/otwarchive/settings/hooks
    5. Find and click the 'Travis CI' hook. You should see that the settings have already been filled in for Travis.
      • If for some reason the settings are not correct, enter your GitHub username in the 'User' section and the token from your Travis-CI profile in the 'Token' and choose 'Update service'
      • At this point, you can now merge in the code changes from the Code Setup section above and Travis-CI will automatically see that you have merged something and look for your .travis.yml file. Once it finds it, your tests will run!

How it looks

If you used the settings above, this is what should happen:

  • When a coder submits a pull request, Travis-CI will automatically grab a copy of the changes and run our full test suite against it.
    • No notifications will be sent out for pull request failures.
  • When a pull request is merged into master, Travis-CI grabs a copy of the new master branch and runs it against our tests.
    • If the build fails, an email will be sent to the otw-coders-extra mailing list saying that the new code does not pass testing.
    • When a build passes without a state change (the build wasn't previously failing), no email will be generated.
    • If the build goes from failing to passing, there will be an email.
    • #otw-dev on freenode will be informed of every pass/fail merger of code.