Skip to content
jshacks.dev
Packages

Automate versions with semantic-release

Let semantic-release pick the next version from commit messages, tag it, publish to npm and write release notes. Needs Node.js 22 or newer.

1 min read
Summarize in AI

Instead of choosing version numbers by hand, semantic-release reads your commit messages and decides. A fix: commit is a patch, feat: is a minor, and a commit with BREAKING CHANGE: in its body is a major.

.releaserc.jsonJSON
{
  "branches": ["main"],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/npm",
    "@semantic-release/github"
  ]
}

Run it from CI after the tests pass:

Shell
npx semantic-release
Text
[semantic-release] › ✔  Published release 1.1.0 on default channel

The last line is the outcome when a feat: commit landed since the previous tag. With only docs: or chore: commits, it prints that there are no relevant changes and publishes nothing. The commit rules are in the semantic-release docs.

This puts the release decision in the commit message, so a vague message like "update stuff" causes no release at all. Pair it with a commit lint check.

The tool needs a token with push rights to the repository. In CI, use the platform's token, and keep full history, since it reads the tags.

Share

More snippets

Packages

Initialize a package with npm init

Initialize a package.json with npm init, skip the questions with the yes flag, and set your own defaults for author and license in npm config.

1 min read
Packages

Generate a changelog from commits

Turn conventional commit messages into a CHANGELOG.md section with conventional-changelog, grouped by feature and fix. Works with any Git history.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.