Skip to content

Makes Travis publish your Node modules on npm for you

License

Notifications You must be signed in to change notification settings

rsp/travis-npm-publish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

travis-npm-publish

This script makes Travis publish your Node modules on npm for you.

Source:

Shortcut:

Right now Travis has a built in way of publishing your modules on npm - see:

But this script may be more convenient to use and easier to customize. You don't need to have the travis CLI tool installed and you don't need to rely on how Travis handles the deployment to npm by default.

You can specify for which GitHub user the publishing is run (though even without it no one anauthorized would not be able to publish your module - it's just to avoid errors in the logs), for which branch or for tagged releases, and the script makes sure that the given tag matches the version from package.json and checks whether this version has already been published before trying to do it.

Usage

It needs to be started as after_success script in .travis.yml - optionally specifying USER and BRANCH:

./travis-npm-publish
./travis-npm-publish USER
./travis-npm-publish USER BRANCH
./travis-npm-publish USER tags

Specifying USER make the script active only for this user's repository. USER may be either a GitHub username or organization name.

Specifying BRANCH make it active for all builds on that branch.

Not specifying BRANCH or giving a special value of tags makes the script active for tagged builds, but only if the tag matches the version specified in package.json.

Authorization

You need to set an environment variable in Travis called NPM_AUTH with a value of the line from your ~/.npmrc that contains the authToken - this line looks like:

//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Note: NPM_AUTH must contain the entire line, not just the token.

You set the variable in Travis in More options / Settings. Make sure you set "Display value in build log" to off and keep this value secret.

Publishing

When the GitHub repo of your module is set up with Travis and the script is set up properly, then publishing a module is a matter of, for example:

npm version patch
git push origin master

The script will not try to publish the module to npm if:

  • one of the required commands is not present
  • the TRAVIS env var is not set (it's set automatically by Travis)
  • the build is a pull request
  • the build fails the tests
  • the NPM_AUTH is not set
  • the GitHub user doesn't match USER (if specified)
  • the branch doesn't match BRANCH (if specified and is other than "tags")
  • the tagged version doesn't match the version in package.json (if using tagged releases)
  • the version specified in package.json has already been published on npm

Of course the script will try but fail to upload the module to npm if the npm user authorized by the authorization token has no right to publish new versions of that module to npm. The USER command line argument is not needed for security, it's just a convenience so that the script will not try to publish the module in situations when it would fail anyway, or in situations where for example you want to publish only from the organization's repo or only by one of the npm collaborators.

Examples

Example .travis.yml - using defaults:

language: node_js
node_js: 4
script: npm test
after_success: "./travis-npm-publish"

Example .travis.yml - publishing only for GitHub repos by USER:

language: node_js
node_js: 4
script: npm test
after_success: "./travis-npm-publish USER"

Example .travis.yml - publishing only for GitHub repos by USER on branch BRANCH:

language: node_js
node_js: 4
script: npm test
after_success: "./travis-npm-publish USER BRANCH"

Issues

For any bug reports or feature requests please post an issue on GitHub.

Author

Rafał Pocztarski
Follow on GitHub Follow on Twitter
Follow on Stack Exchange

License

MIT License (Expat). See LICENSE.md for details.

About

Makes Travis publish your Node modules on npm for you

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages