How-To Guide

How to Automate Releases with semantic-release

Automate versioning and publishing from commit messages with semantic-release, using conventional commits and CI release pipelines.

On this page

  1. Introduction
  2. The Release Is Derived from Commits
  3. Conventional Commit Discipline
  4. The Release Pipeline
  5. Plugins and the Changelog
  6. Monorepos and Multiple Packages
  7. Safety Rails
  8. Common Pitfalls and Conclusion

Introduction

A release that a human performs by hand is a release that happens inconsistently: someone forgets to bump the version, the changelog is out of date, and the tag does not match what was published. semantic-release removes the human from the mechanical part by deriving the version from the commit history: conventional commit messages determine whether the release is a patch, minor or major, and the tool bumps, tags, writes the changelog and publishes in CI. The human still writes the commits that carry the intent.

The Release Is Derived from Commits

semantic-release reads the commits since the last release and classifies each by its conventional commit type. A fix is a patch, a feat is a minor, and a breaking change (marked in the footer or with a !) is a major. The highest bump among the commits determines the new version.

This makes the release deterministic from the history: the same commits produce the same version. It also means the commit messages are the release input, so the discipline that makes the automation work is writing conventional commits, which a commit-msg hook or a commit linter can enforce.

Because the version is derived rather than chosen, there is no separate “decide the version” step to forget, and no ambiguity about whether a change warrants a release. A release happens precisely when the history contains a release-worthy commit since the last tag.

# commit -> version bump
fix: correct the retry backoff           -> patch  (1.4.1 -> 1.4.2)
feat: add retryWithBackoff helper        -> minor  (1.4.2 -> 1.5.0)
feat!: drop support for Node 16
  BREAKING CHANGE: requires Node 18+      -> major  (1.5.0 -> 2.0.0)
# the highest bump among the commits since the last release wins

Conventional Commit Discipline

Conventional commits give every commit a type and an optional scope: “fix(api): handle timeouts”, “feat(utils): add retry”. The message body describes the change and, for a breaking change, a BREAKING CHANGE footer explains what consumers must do. This is the intent the automation consumes.

Enforce the format with a commit-msg hook or a CI check on pull request titles, so a non-conforming commit cannot enter the history and break the release inference. The enforcement is what keeps the automation trustworthy; without it, a mis-typed message produces the wrong version.

# commit-msg hook (commitlint) rejects non-conventional messages.
echo "module.exports = { extends: ['@commitlint/config-conventional'] };" > commitlint.config.cjs
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
# or validate the PR title in CI, since squash-merge uses the PR title

The Release Pipeline

The release runs in CI on the main branch, after tests pass. It reads the commits, computes the next version, updates the changelog and package version, commits those, tags the release, and publishes to the registry or creates a GitHub release. Each step is a plugin, so the pipeline is composed from the parts you need.

Run it only on the main branch and only after the test and build jobs pass, so a release is never made from unverified code. Configure the CI token with the permissions to tag and publish, scoped to the release job.

# GitHub Actions: release after CI passes on main
name: release
on:
  push:
    branches: [main]
jobs:
  release:
    runs-on: ubuntu-latest
    permissions: { contents: write, id-token: write }
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }          # semantic-release needs history
      - uses: actions/setup-node@v4
        with: { node-version: 20, registry-url: 'https://registry.npmjs.org' }
      - run: npm ci && npm test
      - run: npx semantic-release
        env: { NPM_TOKEN: '${{ secrets.NPM_TOKEN }}' }

Plugins and the Changelog

semantic-release is a pipeline of plugins: commit analysis, release note generation, npm publish, GitHub release, and more. The default set covers the common case, and the changelog is generated from the conventional commits, grouped by type, so consumers see features, fixes and breaking changes separately.

The generated changelog is only as good as the commit messages, which is why the conventional commit discipline matters beyond the version number. A changelog grouped from good commits is useful release notes; one from “wip” and “fix stuff” is noise.

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    "@semantic-release/npm",
    ["@semantic-release/git", {
      "assets": ["package.json", "CHANGELOG.md", "package-lock.json"],
      "message": "chore(release): ${nextRelease.version} [skip ci]"
    }],
    "@semantic-release/github"
  ]
}

Monorepos and Multiple Packages

semantic-release assumes one package per repository by default. In a monorepo you need a tool that scopes the commit analysis per package, such as a semantic-release plugin for monorepos or a tool like Changesets that layers intent files on top. A single release across all packages is usually wrong for a monorepo.

The monorepo case is where the automated-version-from-commits model meets its limit: a commit may change several packages, and the version each should get is not obvious from the commit alone. A changeset-style intent file is often the clearer input in a monorepo, and semantic-release fits best in a single-package repository.

# single package  -> semantic-release fits directly
# monorepo        -> a commit may span packages; per-package version is unclear
#   use a monorepo-aware plugin, or Changesets (author declares intent)
#   a single release across all packages is usually wrong

Safety Rails

The automation publishes, so it needs rails: run only on main, only after tests pass, with a token scoped to publishing and a dry-run mode to preview a release without publishing. A dry run on a pull request shows what version and changelog would be produced, which catches a surprising bump before it ships.

Also handle the case where the release fails partway: a tagged version that did not publish, or a publish that failed after the commit. Idempotent steps and a clear failure signal let a re-run complete the release rather than creating a duplicate or a gap.

# Preview a release without publishing (in a PR or locally):
npx semantic-release --dry-run
# prints: next version, the commits that drove it, the release notes
# run for real only on main after tests pass, with a scoped token

Common Pitfalls and Conclusion

Do not run the release on non-main branches or before tests pass. Do not use non-conventional commit messages, or the version and changelog are wrong. Do not forget fetch-depth 0, or semantic-release cannot read the history and infers nothing. And do not use a single-package tool unchanged on a monorepo where commits span packages.

semantic-release derives the version from conventional commits and automates the mechanical release: bump, tag, changelog, publish. Enforce conventional commits, run the pipeline on main after tests, preview with a dry run, and use a monorepo-aware approach when commits span packages. Then releases happen consistently, and the human effort goes into the commits that describe the change.

Sources: semantic-release: Documentation, Conventional Commits, commitlint.

FAQ

How does semantic-release decide the version?
It classifies the commits since the last release: fix is a patch, feat a minor, and a breaking change (BREAKING CHANGE footer or !) a major. The highest bump among the commits determines the next version, so the version is deterministic from the history.
Does semantic-release work in a monorepo?
Not out of the box, because it assumes one package per repository. A commit spanning several packages does not make the per-package bump obvious. Use a monorepo-aware plugin, or Changesets where the author declares the intent, rather than a single-package release across the whole repo.

Related Examples