Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
Arjan van Wijk edited this page Jul 14, 2016 · 1 revision

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.

.travis.yml

The travis configuration is placed in a .travis.yml file, consisting of multiple sections.

  1. Tells travis that we want to run the node_js language.

    language: node_js
  2. 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'
  3. We don't need sudo permissions

    sudo: false
  4. Before running npm install, we want to make sure that:

    • we are running npm@3
    • we install typings (so we can do typings 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
  5. 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
  6. Before running any deploys, we want to prepare our distribution builds.

    before_deploy:
      - npm run build-dist && node ./script/package-dist.js
  7. 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 the upload-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 and tar.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
  8. 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="

Travis Client

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.

  1. First you need to login with your travis account:

    $ travis login
  2. To verify that you are logged in correctly you can check:

    $ travis whoami

npm

  1. Then make sure you are logged in to your npm account with the adduser command:

    $ npm adduser
  2. To verify that you are logged in correctly you can check:

    $ npm whoami
  3. Now we need to grab your auth token so we can encrypt it:

    $ cat ~/.npmrc
    
    # outputs:
    //registry.npmjs.org/:_authToken=<your_auth_token>
  4. 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="
  5. 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 Release

GitHub needs a user auth token with repository permissions to upload the provided files to the release.

  1. Visit the token settings page.

  2. Generate a new token.

    • Enter a descriptive name (e.g. Travis Release - seng-boilerplate)
    • Tick the public_repo checkbox
  3. Copy/paste the listed token.

  4. 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="
  5. 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="

s3

Uploading to S3 requires the bucket access_key_id and secret_access_key, and we want to keep them secure.

  1. 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="
  2. 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="
  3. 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="

Code Climate

  1. For Code Climate you first need to add your repository to Code Climate.

  2. 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.

  3. 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="
  4. 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="

Coveralls

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.

Clone this wiki locally