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-releasein.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
masterbranch - Pre-release from
betabranch
- Release from
- Plugins
@semantic-release/commit-analyzercalculates semantic version from conventional commits@semantic-release/release-notes-generatorgenerates release notes from conventional commits@semantic-release/npmpublishes to configured registry@semantic-release/gitintegrates withgit
- Branches
Trigger release
yarn semantic-release- Use flag
--dry-runto test configuration without uploading to registry - Provide a token for the registry through the
.npmrcorNPM_TOKENenvironment variable - Set
CI=trueto avoid prompts
- Use flag