putaindecode/website — pull request #217 by MoOx (2014-05-29 09:12:39+00:00)
Title: Travis CI auto publish build to gh-pages

This commit include:
- a npm travis script that publish master branch only (otherwise just
run test)
- travis.yml update to launch npm travis script
- a change to tasks/publish.js to handle travis GH_TOKEN
- an update to the README on how to add your token

Now when we commit, we try to publish when it’s on master branch,
otherwise just try the build.

Other owners will add to add their own secure encrypted key:

GH_USERNAME=YOUR_GITHUB_USERNAME
GH_BRANCH=gh-pages

curl -u $GH_USERNAME -d "{\"scopes\":[\"public_repo\"],\"note\":\"push to $GH_BRANCH from travis\"}" https://api.github.com/authorizations

You will be asked to enter your password.

Then you will have something like this

{
"id": 123456,
"url": "https://api.github.com/authorizations/8955171",
"app": {
"name": "push to gh-pages from travis (API)",
"url": "https://developer.github.com/v3/oauth_authorizations/",
"client_id": "00000000000000000000"
},
"token": "YOUR_AWESOME_TOKEN",
"note": "push to gh-pages from travis",
"note_url": null,
"created_at": "2014-05-29T03:55:28Z",
"updated_at": "2014-05-29T03:55:28Z",
"scopes": [
"public_repo"
]
}

Now you will need travis encrypt command that you can get with the ruby
gem `travis` (that have an `encrypt` command) or the npm package
`travis-encrypt`.
For the commands below, lines prefixed by # are for ruby gem, the
following line will be npm version (since I’ve used this one, I’m sure
it as worked - I will see after this commit :D)

#gem install travis
npm i -g travis-encrypt

Then continue with (replace YOUR_AWESOME_TOKEN by your actual token)

GH_REPOSITORY="putaindecode/website"
GH_TOKEN=YOUR_AWESOME_TOKEN
#travis encrypt -r $GH_REPOSITORY GH_TOKEN=$GH_TOKEN
travis-encrypt -r $GH_REPOSITORY -k GH_TOKEN -v $GH_TOKEN

You will get a travis specific token that you should now add in the
env.global section (with your nick please).

Some related doc/examples
http://docs.travis-ci.com/user/ci-environment/#Environment-variables
https://github.com/pimterry/heroku-sinatra-project-template/blob/master/.travis.yml