Skip to content

Instantly share code, notes, and snippets.

@KevinFalank
Forked from ndelage/continuous integration.md
Created February 20, 2014 15:15
Show Gist options
  • Save KevinFalank/9115940 to your computer and use it in GitHub Desktop.
Save KevinFalank/9115940 to your computer and use it in GitHub Desktop.

Continuous Integration for Fun and Profit

Continu-what?

Definition: the practice of frequently integrating one's new or changed code with the existing code repository -Wikipedia

Merging new code into master often sounds awesome, but we've been learning the value of testing and the importance of a passing test suite.

But, as your projects grow, your test suite should grow as well. We're all lazy and forget to run the entire test suite everytime we create a new commit. For large projects, running the entire test suite can take hours. So we do what all lazy people do, make a computer to the work for us.

But Nate, I just wanna merge!

...and I don't want to wait for a million tests to run, don't you realize I have things to do??

Super Build Server to your rescue

A build server will be responsible to run the entire test suite after ever commit and let you know if any tests failed. That way when your change to the User model breaks the Vote creation integration test, you'll be notified (email) without having to run every test yourself.

If your build passes, then you know you're ready to merge into master.

Keep master green

As you begin to push your apps to production, you don't want to introduce any bugs in your master branch (keep those in your feature branches). With master green you can always deploy to production without fear.

OK. I'm convinced. I can haz build server?

Yes you can. Travis-CI is an automated, hosted build service that we'll be using.

Requirements

  • a public repository
  • .travis.yml file (build configuration)
  • tests (duh)

Changes to Your Repo

  1. Create, add and commit a Travis-CI config file, named .travis.yml. See the sample .travis.yml at the bottom of this Gist.

Steps on Travis CI

  1. Have the owner of your repo visit travis-ci.org and click the login button in the upper right. Travis-CI will ask you to authenticate with Github so it can view your public repositories.
  2. From Travis CI, click on Accounts under your username in the upper right.
  3. Here, you'll see a list of your repositories. If you don't see the repository you'd like to test, click the Sync Now button.
  4. Once the repository is listed, enable Travis CI with the toggle swtich.

Steps on Github

  1. Then go back to your repository (on Github) and click the Settings link (on the right hand side-bar).
  2. Then click on Service Hooks (left hand side-bar).
  3. Scroll wayyyy down and find the Travis hook. Click on it.
  4. Click the Test Hook button

Now go back to Travis-CI and within a few moments you should see your tests running. Going forward, your entire test suite will run each time you push a new commit or feature branch up to Github.

Sample .travis.yml file for a RoR project:

language: ruby
rvm:
  - 2.0.0
env:
  - DB=postgresql
script:
  - bundle exec rake spec
before_script:
  - bundle exec rake db:create RAILS_ENV=test
  - bundle exec rake db:migrate
  - bundle exec rake db:test:prepare
bundler_args: --binstubs=./bundler_stubs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment