There's an issue with semantic-release which sometimes prevents it from getting proper commits set for new version. This happens if published package.json doesn't have gitHead property. This is undocumented property that NPM usually autopopulate when publishing but sometimes it doesn't - in this case semantic-release thinks the whole commits history is relevant to given release. One relevant issue logged in semantic-release Github is #280.
This fork works around this issue by doing 2 things:
- let semantic-release pre pre-write gitHead property together with version
- if semantic-release pre sees that the last released version doesn't have gitHead property, try to use the relevant vX.Y.Z git tag
The PR is created but until it's merged this fork can be useful.
npm remove --save semantic-release npm install --save @artemv/semantic-release
fully automated package publishing
Trust us, this will change your workflow for the better.
Out of the box this is just about commit-messages, but you can do so much more.
- Detect breaking changes using the test suite of your last release: cracks
- Detect breaking changes using your dependents’ test suites: Help out! Implement the dont-break plugin
- Detect breaking changes diffing your JSDoc interface: Help out! Implement the india plugin
- Abort releases with insufficient test coverage: Help out! Implement the istanbul plugin
- Abort releases with vulnerable dependencies in the tree: Help out! Implement the nsp plugin
- Everything you can imagine: Build Plugins!
||You manually decide what the next version is. You have to remember what major, minor and patch means. You have to remember to push both commits and tags. You have to wait for the CI to pass.|
||You describe the changes you’ve made. A new version is automatically published with the correct version number.|
This removes the immediate connection between human emotions and version numbers, so strictly following the SemVer spec is not a problem anymore – and that’s ultimately
How does it work?
Instead of writing meaningless commit messages, we can take our time to think about the changes in the codebase and write them down. Following formalized conventions it is then possible to generate a helpful changelog and to derive the next semantic version number from them.
semantic-release is setup it will do that after every successful continuous integration build of your master branch (or any other branch you specify) and publish the new version for you. This way no human is directly involved in the release process and your releases are guaranteed to be unromantic and unsentimental.
If you fear the loss of control over timing and marketing implications of software releases you should know that
semantic-release supports release channels using
npm’s dist-tags. This way you can keep control over what your users end up using by default, you can decide when to promote an automatically released version to the stable channel, and you can choose which versions to write blogposts and tweets about. You can use the same mechanism to support older versions of your software, for example with important security fixes.
This is what happens in series:
|New code is pushed and triggers a CI build.||Based on all commits that happened since the last release, the new version number gets written to the
||The new version gets published to
||A changelog gets generated and a release (including a git tag) on GitHub gets created.|
Note: The current release/tag implementation is tied to GitHub, but could be opened up to Bitbucket, GitLab, et al. Feel free to send PRs for these services.
Default Commit Message Format
Each commit message consists of a header, a body and a footer. The header has a special format that includes a type, a scope and a subject (full explanation):
<type>(<scope>): <subject> <BLANK LINE> <body> <BLANK LINE> <footer>
fix(pencil): stop graphite breaking when too much pressure applied
Minor Feature Release
feat(pencil): add 'graphiteWidth' option
Major Breaking Release
perf(pencil): remove graphiteWidth option BREAKING CHANGE: The graphiteWidth option has been removed. The default graphite width of 10mm is always used for performance reason.
npm install -g semantic-release-clicd your-modulesemantic-release-cli setup
These options are currently available:
branch: The branch on which releases should happen. Default:
debug: If true doesn’t actually publish to npm or write things to file. Default:
githubToken: The token used to authenticate with GitHub. Default:
githubUrl: Optional. Pass your GitHub Enterprise endpoint.
githubApiPathPrefix: Optional. The path prefix for your GitHub Enterprise API.
A few notes on
npmtoken can only be defined in the environment as
NPM_TOKEN, because that’s where
npmitself is going to read it from.
In order to publish to a different
npmregistry you can specify that inside the
If you want to use another dist-tag for your publishes than
'latest'you can specify that inside the
semantic-releasegenerally tries to orientate itself towards
npm– it inherits the loglevel for example.
There are numerous steps where you can customize
semantic-release’s behaviour using plugins. A plugin is a regular option, but passed inside the
release block of
semantic-release pre --analyze-commits="npm-module-name"
A plugin itself is an async function that always receives three arguments.
pluginConfig: If the user of your plugin specifies additional plugin config in the
verifyConditionsexample above) then it’s this object.
config: A config object containing a lot of information to act upon.
env: All environment variables
npm: Select npm configuration bits like
- For certain plugins the
configobject contains even more information. See below.
callback: If an error occurs pass it as first argument. Otherwise pass your result as second argument.
This plugin is responsible for determining the type of the next release. It additionally receives a
commits array inside
config. One commit is an object with a
hash property. Call the callback with
null if nothing changed.
While it may be tempting to use
'prerelease' as part of a release process, this is strongly discouraged. A better approach is to use dist-tags to create release channels (such as 'latest', 'next', 'stable') and to return only
'minor' from the commit analyzer.
Have a look at the default implementation.
This plugin is responsible for generating release notes. Call the callback with the notes as a string. Have a look at the default implementation.
This plugins is responsible for verifying that a release should happen in the first place. For example, the default implementation verifies that the publish is happening on Travis, that it’s the right branch, and that all other build jobs succeeded. There are more use cases for this, e.g. verifying that test coverage is above a certain threshold or that there are no vulnerabilities in your dependencies. Be creative.
Passing an array of plugins will run them in series.
This plugin is responsible for verifying a release that was determined before and is about to be published. There is no default implementation. It additionally receives
commits is the same as with analyzeCommits,
nextRelease contains a
'major') and the new version (e.g.
lastRelease contains the old
gitHead at the time of the release and the npm dist-
'latest'). Using this information you could detect breaking changes or hold back certain types of releases. Again: Be creative.
Passing an array of plugins will run them in series.
This plugin is responsible for determining a package’s last release version. The default implementation uses the last published version on a npm registry.
I think you might frequently ask questions like these
Why is the
package.json’s version not updated in my repository?
npm docs even state:
The most important things in your package.json are the name and version fields. Those are actually required, and your package won’t install without them. – npm docs
While this entirely true the version number doesn’t have to be checked into source control.
semantic-release takes care of the version field right before
npm publish uses it – and this is the only point where it really is required.
Is there a way to preview which version would currently get published?
If you run
npm run semantic-release locally a dry run gets performed, which logs the version that would currently get published.
Can I run this on my own machine rather than on a CI server?
Of course you can, but this doesn’t necessarily mean you should. Running your tests on an independent machine before releasing software is a crucial part of this workflow. Also it is a pain to set this up locally, with tokens lying around and everything. That said, you can run the scripts with
--debug=false explicitly. You have to export
Can I manually trigger the release of a specific version?
You can trigger a release by pushing to your GitHub repository. You deliberately cannot trigger a specific version release, because this is the whole point of
semantic-release. Start your packages with
1.0.0 and semver on.
Is it really a good idea to release on every push?
It is indeed a great idea because it forces you to follow best practices. If you don’t feel comfortable making every passing feature or fix on your master branch addressable via
npm you might not treat your master right. Have a look at branch workflows. If you still think you should have control over the exact point in time of your release, e.g. because you are following a release schedule, you can release only on the
release branch and push your code there in certain intervals, or better yet use dist-tags.
Why should I trust
semantic-release with my releases?
semantic-release has a full unit- and integration-test-suite that tests actual
npm publishes against the npm-registry-couchapp on all major node.js versions from
^0.10 on. A new version won’t get published if it doesn’t pass on all these engines.
Use this in one of your projects? Include one of these badges in your README.md to let people know that your package is published using
MIT License 2015 © Stephan Bönnemann and contributors