Node package versioning with `semantic-release`
September 30, 2020
We will setup semantic-release
to calculate a new semantic version from out commits and release that to npm
.
Calculating version
As long as our commits follow the conventional commit style, semantic-release
can infer whether the next semantic version will be a major, minot or patch.
Semantic Versions
Semantic versions are a convention that indicates whether the next version is a breaking change or not.
They are in the format of major.minor.patch
(e.g. 1.23.456
).
Change | Description |
---|---|
major | breaking |
minor | non-breaking addition |
patch | non-breaking fix |
Conventional Commits
Conventional commits prefix a git
commit message with a label that indicates the type of change being committed.
feat: add xyz featurefix: handle divide by 0 case# breaking change (!)feat!: drop v1 api
Label | Change | Description |
---|---|---|
feat! or fix! | major | break |
feat | minor | non-breaking addition |
fix | patch | non-breaking fix |
Setup
Install
yarn install --dev semantic-release @semantic-release/gitConfigure registry in
package.json
"name": "@github-username/package""publishConfig": {"registry": "https://npm.pkg.github.com"}Configure
semantic-release
in.releaserc.json
{"release": {"branches": [{"name": "master"},{"name": "beta","prerelease": true}],"debug": true},"plugins": ["@semantic-release/commit-analyzer","@semantic-release/release-notes-generator","@semantic-release/npm","@semantic-release/git"]}- Branches
- Release from
master
branch - Pre-release from
beta
branch
- Release from
- Plugins
@semantic-release/commit-analyzer
calculates semantic version from conventional commits@semantic-release/release-notes-generator
generates release notes from conventional commits@semantic-release/npm
publishes to configured registry@semantic-release/git
integrates withgit
- Branches
Trigger release
yarn semantic-release- Use flag
--dry-run
to test configuration without uploading to registry - Provide a token for the registry through the
.npmrc
orNPM_TOKEN
environment variable - Set
CI=true
to avoid prompts
- Use flag