Skip to content

Instantly share code, notes, and snippets.

@zaguiini
Last active November 2, 2019 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaguiini/c18ed6e2d70a8bcc0bf37175478f1917 to your computer and use it in GitHub Desktop.
Save zaguiini/c18ed6e2d70a8bcc0bf37175478f1917 to your computer and use it in GitHub Desktop.
Travis CI NPM workflow

Travis CI - NPM workflow

This workflow does, in the following order:

  • install your packages
  • run the lint command
  • run the test command
  • publishes the package with the version defined in the release tag
  • publishes the new version code on github (updates the package.json to match the latest tag)

It will only trigger the deploy phase on the master branch when there's the release tag present. Otherwise it will just build and test your files.

Environment variables

You'll need to set, on the repository settings, the following env variables:

language: node_js
node_js:
- node
cache:
yarn: true
directories:
- node_modules
install:
- yarn
script:
- yarn lint
- yarn test
- yarn build
before_deploy:
- git remote remove origin
- git remote add origin https://${GH_TOKEN}@github.com/your-user/your-repository.git
- git fetch && git checkout master
- git config user.name "Travis CI"
- git config user.email "travis@travis-ci.org"
deploy:
provider: script
script: "npm config set '//registry.npmjs.org/:_authToken' '${API_TOKEN}' && yarn publish --new-version ${TRAVIS_TAG}"
skip_cleanup: true
on:
tags: true
branch: master
after_deploy:
- git commit --amend -m "v$TRAVIS_TAG [skip ci]"
- git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment