Travis CI - olendorf/jsonb_elasticsearch_demo GitHub Wiki

Travis CI is a nice continuous integration service. It integrates with Github, so to get started just head over to their webpage and sign in. On your dashboard page you'll see a My Repositories list, click on the + (plus) sign to the right of that. You'll get a list of all your public repositories. To start, turn on the repository for this project. Create a new branch and push it up to Github.

    $ git checkout -b travis-ci-#7
    $ git push origin 

In a few seconds or so you should see that your build failed to pass because there is no .travis.yml file. So lets add that. There were issues with the pre-installed version of Elasticsearch. Installing a different version and moving files around may be ham-handed but works. Finally, to make sure we run the slow elastic search tests we make sure and run rspec with the correct tags.

language: ruby
sudo: required
rvm:
  - 2.3.0
services:
  - postgresql
  - elasticsearch
addons:
  postgresql: "9.4"   # We need the more recent version of postgres
before_install: 
  # Install a more recent version of elasticsearch, also couldn't find preinstaleld version 
  - curl -O https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.3.5/elasticsearch-2.3.5.deb && sudo dpkg -i --force-confnew elasticsearch-2.3.5.deb && sudo service elasticsearch restart
before_script:
  # The installation fails to create a scripts directory or copy the elasticsearch.yml
  # or logging.yml files over. THis fixes that.
  - sudo mkdir -p /usr/share/elasticsearch/config/scripts   
  - sudo cp /etc/elasticsearch/elasticsearch.yml /usr/share/elasticsearch/config
  - sudo cp /etc/elasticsearch/logging.yml /usr/share/elasticsearch/config
  - psql -c 'create database app_test;' -U postgres
  - sleep 10 # To make sure Elasticsearch instance is ready
script: bundle exec rspec --tag slow   # we should run all the tests in CI

If you commit that and push it up to your Github repository it should be green.

As you probably noticed, it can take a long time to run. If you don't want it running on every push you can click on the settings (the horizontal bars on the top right) and turn off build on pushes. That will set it so it only build on pull requests. Also, if you follow the pull request comments, you can see that your Github repo is providing updates from Travis CI. Or you could filter branches, which will be my solution. Add the following lines to your .travis.yml file.

    # Add this to .travis.yml
    branches:
      only: 
        - master
        - develop

Now you should only be tracking the master branch, develop branch and any pull requests to develop or master.

    $ git add -A
    $ git commit -m "integrated with travis ci"
   
    # Do your github pull request/merge as you like 

    $ git checkout develop
    $ git pull origin develop
    $ git branch -d travis-ci-#7