-
Notifications
You must be signed in to change notification settings - Fork 3
Travis
This project uses Travis to build, test and publish its code to npm. Travis is free for public Github repositories.
It runs on all commits, shows the build status for pull requests, and publishes to npm when a new tag/release is created.
Travis only runs the npm test
script, so we have configured that script
to run everything we want Travis to check. Besides the unit tests, we
also run our validations and linters.
The travis configuration is placed in a .travis.yml
file, consisting
of multiple sections.
-
Tells travis that we want to run the node_js language.
language: node_js
-
We want to run on node 4 and 5, and on the current stable (6 at the moment), so we test our code on all the versions.
node_js: - 'stable' - '4' - '5'
-
We don't need sudo permissions
sudo: false
-
Before running
npm install
, we want to make sure that:- we are running npm@3
- we install
typings
(so we can dotypings install
- we want to install the
codeclimate-test-reporter
, so we can send our coverage reports
before_install: - if [[ `npm -v` != 3* ]]; then npm i -g npm@3; fi - npm install -g typings - npm install -g codeclimate-test-reporter
-
After our
npm test
script has run, we want to upload our code coverage results.after_script: - codeclimate-test-reporter < coverage/lcov.info - node_modules/.bin/coveralls < coverage/lcov.info
-
Before running any deploys, we want to prepare our distribution builds.
before_deploy: - npm run build-dist && node ./script/package-dist.js
-
This 3 deploy settings have some things in common:
- We want to
skip_cleanup
, so all generated artifacts are left untouched; we need them for the deploys. - We only want to deploy on git tags, and only when we run on node 4 (or else we execute the deploys on all the version targets)
deploy: - provider: ... on: tags: true node: '4' skip_cleanup: true
The npm deploy has no special settings besides the credentials.
For the s3 deploy we specify the
local_dir
(what we want to upload) and theupload-dir
(where we want to upload it to).- provider: s3 local_dir: 'dist' upload-dir: 'seng/libs'
For GitHub Release deploy we want to specify the
zip
andtar.gz
files to attach to the release. We use the wildcard to match any seng module, and to make that work we must add the (undocumented)file_glob
flag.- provider: releases file: - "seng-*.zip" - "seng-*.tar.gz" file_glob: true
- We want to
-
At the bottom we specify settings for the code climate plugin, and in this case it's only the repo_token that the script needs.
addons: code_climate: repo_token: secure: "YcN...Zb="
Because we want to keep all the keys and tokens secret, we generate a secure tokens with the Travis Client, a CLI written in ruby.
Before we can do this, we must make sure that the repository is added to Travis, because Travis needs the repository owner/name info to make sure the encrypted values only work for that repository.
-
First you need to login with your travis account:
$ travis login
-
To verify that you are logged in correctly you can check:
$ travis whoami
-
Then make sure you are logged in to your npm account with the adduser command:
$ npm adduser
-
To verify that you are logged in correctly you can check:
$ npm whoami
-
Now we need to grab your auth token so we can encrypt it:
$ cat ~/.npmrc # outputs: //registry.npmjs.org/:_authToken=<your_auth_token>
-
Then let's encrypt that token using the travis encrypt command:
$ travis encrypt <your_auth_token> Detected repository as mediamonks/seng-boilerplate, is this correct? |yes| Please add the following to your .travis.yml file: secure: "YcN...Zb="
-
Now copy that last line, paste it into your
.travis.yml
, and make sure it looks something like this:deploy: provider: npm email: "john@doe.com" api_key: secure: "YcN...Zb="
GitHub needs a user auth token with repository permissions to upload the provided files to the release.
-
Visit the token settings page.
-
Generate a new token.
- Enter a descriptive name (e.g.
Travis Release - seng-boilerplate
) - Tick the
public_repo
checkbox
- Enter a descriptive name (e.g.
-
Copy/paste the listed token.
-
Then let's encrypt that token using the travis encrypt command:
$ travis encrypt <your_github_token> Detected repository as mediamonks/seng-boilerplate, is this correct? |yes| Please add the following to your .travis.yml file: secure: "YcN...Zb="
-
Now copy that last line, paste it into your
.travis.yml
, and make sure it looks something like this:deploy: - provider: releases api_key: secure: "YcN...Zb="
Uploading to S3 requires the bucket access_key_id
and secret_access_key
, and we want to
keep them secure.
-
Let's encrypt the
access_key_id
using the travis encrypt command:$ travis encrypt <s3_access_key_id> Detected repository as mediamonks/seng-boilerplate, is this correct? |yes| Please add the following to your .travis.yml file: secure: "YcN...Zb="
-
Then let's encrypt the
secret_access_key
using the travis encrypt command:$ travis encrypt <s3_secret_access_key> Detected repository as mediamonks/seng-boilerplate, is this correct? |yes| Please add the following to your .travis.yml file: secure: "ZbY...cN="
-
Now copy that last line, paste it into your
.travis.yml
, and make sure it looks something like this:deploy: - provider: s3 access_key_id: secure: "YcN...Zb=" secret_access_key: secure: "ZbY...cN="
-
For Code Climate you first need to add your repository to Code Climate.
-
Then go to the repo settings, Test coverage section, and the JavaScript tab. Copy the
CODECLIMATE_REPO_TOKEN
listed in step 3 on that page. -
Then let's encrypt that token using the travis encrypt command:
$ travis encrypt <your_codeclimate_repo_token> Detected repository as mediamonks/seng-boilerplate, is this correct? |yes| Please add the following to your .travis.yml file: secure: "YcN...Zb="
-
Now copy that last line, paste it into your
.travis.yml
, and make sure it looks something like this:addons: code_climate: repo_token: secure: "YcN...Zb="
For Coveralls you just need to make sure your repository is added is added in Coveralls. The coveralls npm module will take care of everything; when run inside Travis it has access to the repo info so it can only upload coverage results to that repository.