Continuous Integration for Open Source Projects with Travis-CI

#OSCON

@GeekGoneNomad

Kyle Tyacke

API Evangelist Akamai

Full Stack Developer

Node Enthusiast

Beer Geek

#OSCON

@GeekGoneNomad

#OSCON

@GeekGoneNomad

#OSCON

@GeekGoneNomad

#OSCON

@GeekGoneNomad

New Github Project

#OSCON

@GeekGoneNomad

Pull Requests

#OSCON

@GeekGoneNomad

Merge Pull Request

#OSCON

@GeekGoneNomad

Merge Conflict

#OSCON

@GeekGoneNomad

Stale Pull Requests

What We're Gonna Cover

#OSCON

@GeekGoneNomad

Continuous Integration (CI)

Travis CI

Preparing for CI

Working with Travis CI

Q&A

Continuous Integration

#OSCON

@geekgonenomad

#OSCON

@geekgonenomad

Continuous Integration

...a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

–https://www.thoughtworks.com/continuous-integration

#OSCON

@geekgonenomad

Continuous Integration

...a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

#OSCON

@geekgonenomad

Continuous Integration

...a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

#OSCON

@geekgonenomad

Continuous Integration

...a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

#OSCON

@geekgonenomad

Continuous Integration

...a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

#OSCON

@geekgonenomad

Continuous Integration

...a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

#OSCON

@GeekGoneNomad

#OSCON

@GeekGoneNomad

Travis CI

#OSCON

@GeekGoneNomad

Travis CI

...a hosted continuous integration service

that's free for open source projects.

#OSCON

@GeekGoneNomad

Travis CI

...a hosted continuous integration service that's free for open source projects.

#OSCON

@GeekGoneNomad

Travis CI

...a hosted continuous integration service

that's free for open source projects.

#OSCON

@GeekGoneNomad

Open Source

Multi-Language

Pull Requests

Simplified Deployments

Easy

Travis CI

Pull Requests

#OSCON

@GeekGoneNomad

#OSCON

@GeekGoneNomad

Pull Request Workflow

#OSCON

@GeekGoneNomad

Pull Request Success

#OSCON

@GeekGoneNomad

Pull Request Success

#OSCON

@GeekGoneNomad

Pull Request Failure

#OSCON

@GeekGoneNomad

language: node_js
node_js:
  - "stable"
  - "5.1"
  - "4"

Language  Support

Node.js

  • PHP

  • Python

  • Java

  • Ruby

  • GO

  • Objective-C

  • Perl

  • Android

  • C

  • C#

  • C++

  • Clojure

  • Crystal

  • Haskell

  • Julia

  • Perl6

  • Rust

  • Scala

  • Haxe

  • Dart

  • ...

Adding Travis

to Your Project

#OSCON

@GeekGoneNomad

#OSCON

@GeekGoneNomad

Enable Travis

#OSCON

@GeekGoneNomad

# THIS PROJECT USES NODE.JS
language: node_js

# BUILD USING THE LATEST STABLE VERSION OF NODE
node_js:
  - "stable"

# RUN OUR TESTS BY CALLING MOCHA 
script: mocha

.travis.yml

#OSCON

@GeekGoneNomad

Build Success

#OSCON

@GeekGoneNomad

Build Failure

#OSCON

@GeekGoneNomad

0.37s$ git clone --depth=50 --branch=master https://github.com/ktyacke/travis-node-example.git ktyacke/travis-node-example
Cloning into 'ktyacke/travis-node-example'...
remote: Counting objects: 75, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 75 (delta 1), reused 1 (delta 1), pack-reused 68
Unpacking objects: 100% (75/75), done.
Checking connectivity... done.
$ cd ktyacke/travis-node-example
$ git checkout -qf 55d11fa1be7c186db1bd4b154b3cc343be17534a
This job is running on container-based infrastructure, which does not allow use of 'sudo', setuid and setguid executables.
If you require sudo, add 'sudo: required' to your .travis.yml
See https://docs.travis-ci.com/user/workers/container-based-infrastructure/ for details.
1.60s$ nvm install stable
######################################################################## 100.0%
Checksums empty
Now using node v5.8.0
$ node --version
v5.8.0
$ npm --version
3.7.3
$ nvm --version
0.23.3
install
2.57s$ npm install 
npm WARN deprecated graceful-fs@2.0.3: graceful-fs version 3 and before will fail on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possible.
travis-node-example@1.0.0 /home/travis/build/ktyacke/travis-node-example
├─┬ chai@3.5.0 
│ ├── assertion-error@1.0.1 
│ ├─┬ deep-eql@0.1.3 
│ │ └── type-detect@0.1.1 
│ └── type-detect@1.0.0 
└─┬ mocha@2.4.5 
  ├── commander@2.3.0 
  ├─┬ debug@2.2.0 
  │ └── ms@0.7.1 
  ├── diff@1.4.0 
  ├── escape-string-regexp@1.0.2 
  ├─┬ glob@3.2.3 
  │ ├── graceful-fs@2.0.3 
  │ ├── inherits@2.0.1 
  │ └─┬ minimatch@0.2.14 
  │   ├── lru-cache@2.7.3 
  │   └── sigmund@1.0.1 
  ├── growl@1.8.1 
  ├─┬ jade@0.26.3 
  │ ├── commander@0.6.1 
  │ └── mkdirp@0.3.0 
  ├─┬ mkdirp@0.5.1 
  │ └── minimist@0.0.8 
  └── supports-color@1.2.0 
0.60s$ npm test
> travis-node-example@1.0.0 test /home/travis/build/ktyacke/travis-node-example
> mocha
  hello
  ✓ Returns a string of hello plus the name that was passed.
  1 passing (10ms)
The command "npm test" exited with 0.
Done. Your build exited with 0.

Travis Build

.travis.yml

#OSCON

@GeekGoneNomad

#OSCON

@GeekGoneNomad

INSTALL

before_install

install

BUILD

before_script

script

after_success 

after_failure

after_script

DEPLOY 

before_deploy

deploy

after_deploy

Travis Build Lifecycle

#OSCON

@GeekGoneNomad

INSTALL

before_install

install

BUILD

before_script

script

after_success 

after_failure

after_script

DEPLOY 

before_deploy

deploy

after_deploy

Travis Build Lifecycle

#OSCON

@GeekGoneNomad

INSTALL

before_install

install

BUILD

before_script

script

after_success

after_failure

after_script

DEPLOY 

before_deploy

deploy

after_deploy

Travis Build Lifecycle

#OSCON

@GeekGoneNomad

INSTALL

before_install

install

BUILD

before_script

script

after_success 

after_failure

after_script

DEPLOY

before_deploy

deploy

after_deploy

Travis Build Lifecycle

#OSCON

@GeekGoneNomad

The Travis Client

#OSCON

@GeekGoneNomad

Testing

#OSCON

@GeekGoneNomad

Testing

 

language: node_js

node_js:
  - stable

script: 
  - mocha

#OSCON

@GeekGoneNomad

Testing Success

#OSCON

@GeekGoneNomad

Testing Failure

#OSCON

@GeekGoneNomad

Linting

#OSCON

@GeekGoneNomad

Linting

language: node_js

node_js:
  - stable

before_script:
  - npm install -g jscs

script: 
  - jscs src
  - mocha

#ConfHandle

@geekgonenomad

Linting Failure

#OSCON

@GeekGoneNomad

Linting Failure

#OSCON

@GeekGoneNomad

Database Support

  • MySQL

  • PosgreSQL

  • SQLite3

  • MongoDB

  • CouchDB

  • Redis

#OSCON

@GeekGoneNomad

Databases

services:
  - couchdb

before_script:
  - curl -X PUT http://127.0.0.1:5984/travis-node-demo
  - curl -X GET http://127.0.0.1:5984/_all_dbs

#OSCON

@GeekGoneNomad

Databases

#OSCON

@GeekGoneNomad

Databases

$ sudo service couchdb start
couchdb start/running, process 2303

$ curl -X PUT http://127.0.0.1:5984/travis-node-demo
{"ok":true}

$ curl -X GET http://127.0.0.1:5984/_all_dbs
["_replicator","_users","travis-node-demo"]

#OSCON

@GeekGoneNomad

Deployment

  • Heroku

  • NPM

  • PyPi

  • Amazon S3

  • RubyGems

  • Github 

#OSCON

@GeekGoneNomad

Deployment

before_deploy:
  - npm version patch

deploy:
  provider: npm
  email: ktyacke@gmail.com
  api_key:
    secure: XXXXXXXXXXXXX
  on:
    tags: true
    repo: ktyacke/travis-node-example
    all_branches: true

#OSCON

@GeekGoneNomad

Deployment

# ENCRYPT AND ADD KEY TO CONFIG
travis encrypt YOUR_API_KEY --add deploy.api_key

# USE CLI TO ADD DEPLOYMENT PROVIDER
travis setup npm

#OSCON

@GeekGoneNomad

Deployment

#OSCON

@GeekGoneNomad

Installing deploy dependencies
Preparing deploy
NPM version: 3.8.3
Authenticated with email ktyacke@gmail.com

Cleaning up git repository with `git stash --all`. If you need build artifacts for deployment, set `deploy.skip_cleanup: true`. 
See https://docs.travis-ci.com/user/deployment/#Uploading-Files.

Deploying application
NPM API key format changed recently. If your deployment fails, check your API key in ~/.npmrc.
http://docs.travis-ci.com/user/deployment/npm/
~/.npmrc size: 48
+ travis-node-example@1.0.4

Deployment

#OSCON

@GeekGoneNomad

Notifications

  • Email

  • IRC

  • HipChat

  • Slack

  • Webhooks

#OSCON

@GeekGoneNomad

Notifications

notifications:
  email:
    recipients:
      - foo@bar.com
    on_success: always
    on_failure: always

  slack:
    rooms:
      - secure: XXXXXXXXXXXXX
    on_success: always
    on_failure: always
    on_start: always

#OSCON

@GeekGoneNomad

Notifications

# ENCRYPT AND ADD TOKEN TO CONFIG
travis encrypt "<account>:<token>" --add notifications.slack.rooms

#OSCON

@GeekGoneNomad

Notifications

#OSCON

@GeekGoneNomad

Notifications

#OSCON

@GeekGoneNomad

Build Status Badges

#MakeOSFunAgain

#OSCON

@GeekGoneNomad

kyle@geekgonenomad.com

Kyle Tyacke

Examples and Source

@GeekGoneNomad

Continuous Integration with Travis-CI

By Kyle Tyacke

Continuous Integration with Travis-CI

  • 2,078