I use semantic-release
for most of my projects. It has completely freed me from thinking about the
NPM publish step, which now happens automatically. But sometimes I do not go
semantic-release-cli setup command, instead I prefer to
set things up manually. This avoids the NPM and GitHub logins, or installing
semantic-release-cli global tool.
This guide assumes you are using the public NPM registry (even with private scoped modules) and GitHub. This guide also assumes Travis CI, although other CIs are supported too.
Grab the NPM auth token
Login into NPM registry from the command line. This adds an auth token to
.npmrc file in the home directory. Grab the token
$ cat ~/.npmrc | grep _authToken //registry.npmjs.org/:_authToken=<XXXX-YYYY....>
Add GitHub access token
Open the browser at
and add a new personal token. Give it a name, like
You should allow the following permissions to make sure the CI can push
new tags and release notes to GitHub. Only check the sub permissions, not the
top level groups.
Make sure to copy the generated token, since it will not be displayed again.
Setup the CI project
Enable the CI build for the given project. Go to the CI project settings
and add two environment variables
the values you saved previously.
Add the CI-specific configuration file to the repository. The CI should run the script "semantic-release" after successful build of the master branch. For example, here is a typical Travis configuration file.
sudo: false language: node_js cache: directories: - node_modules notifications: email: false node_js: - '6' before_script: - npm prune script: - npm run lint after_success: - npm run semantic-release branches: except: - "/^v\\d+\\.\\d+\\.\\d+$/"
Or if you use CircleCI using condition-circle you can use the following settings file
machine: node: version: 6 test: post: - npm run semantic-release || true
You should also add the CI badge to the project's README file. For example, here is the Markdown for a sample project (replace the user and project names). I also add "semantic release" badge.
[ ]][ ]
Add the release module
The semantic release module will actually inspect the GitHub commit log since the previous NPM publish, determine the new (if any) package version and will actually push the new version.
$ npm i -D semantic-release
Then add a new script command to
I also recommend replacing whatever the current version listed in the package file with a text clearly informing that the actual version is determined automatically.
Push a new commit to the GitHub and watch the CI publish it.