CI/CD and automation · Intermediate · 17 min
Automate version numbers, changelogs and releases with semantic-release
By Padding · Updated 18 Nov 2026
Node.js 26.13 · semantic-release 26.0.1 · GitHub Actions
You will configure semantic-release 26 so that Conventional Commit messages decide each version number, write CHANGELOG.md and tag the release, rehearse it against a local remote, and add the GitHub Actions workflow that releases from main.
On this page
Picking a version number by hand works until a release goes out on a Friday evening and nobody remembers whether the change was a fix or a feature. semantic-release removes the decision. It reads the commit messages since the last release tag, works out whether the next version is a patch, minor or major bump, writes the release notes, tags the commit and publishes the release. You stop choosing numbers and start writing clear commit messages instead.
This tutorial picks up where /tutorials/version-releases-with-semantic-versioning-and-a-changelog does the same job by hand. You build a tiny Node.js project in a throwaway folder, ~/release-demo, with a bare Git repository beside it standing in for GitHub. That lets you watch real releases happen, tags and changelog included, before any of it touches a repository other people use. The last two steps move the setup to GitHub Actions.
Step 1 · Create the project and a practice remote
semantic-release has to see a remote: before it does anything it checks that it is allowed to push there. A bare repository on disk is a remote like any other, so make one, then the project that pushes to it:
mkdir -p ~/release-demo
cd ~/release-demo
git init --bare -b main origin.git
mkdir greet
cd greet
git init -b main
git remote add origin "file://$HOME/release-demo/origin.git"
npm init -y
npm pkg set name=greet version=0.0.0-development
npm pkg set private=true --json
printf 'node_modules\n' > .gitignoreThe version 0.0.0-development is a placeholder. From now on the real version lives in Git tags, and semantic-release writes it into package.json at release time. private: true stops anyone running npm publish on this demo by mistake.
Add the code you will release:
cat > index.js <<'JS'
function greet(name) {
return `Hello, ${name}`
}
module.exports = { greet }
JSCheck it worked
node -e "console.log(require('./index.js').greet('Amara'))"
git remote -vNode prints Hello, Amara, and Git lists origin twice (fetch and push), both pointing at file://…/release-demo/origin.git.
Step 2 · Write commits in the Conventional Commits format
semantic-release does not read your code. It reads commit messages written to the Conventional Commits 1.0.0 format, a type, an optional scope in brackets, a colon and a short summary:
feat(cli): add a --shout option
fix: keep the trailing newline in output
docs: explain the config fileThree things decide the version:
fix:makes a patch release,1.4.2to1.4.3.feat:makes a minor release,1.4.2to1.5.0.- A footer that starts
BREAKING CHANGE:, or a!after the type (feat!:), makes a major release,1.4.2to2.0.0.
Every other type, such as docs, test, build, ci, refactor or chore, is recorded in history but releases nothing on its own. When several commits pile up between releases, the biggest one wins: one breaking change among ten fixes still means a major release.
Make the first commit a feature and push it:
git add .
git commit -m "feat: add greet function"
git push -u origin mainIf your team writes commit messages in several languages, keep the type keyword (feat, fix) in English, because that is what the tools match, and write the summary in whichever language your team reads best. The summary is copied into the changelog as written.
Check it worked
git log --onelineYou see one commit, feat: add greet function. A typo in the type, such as feature: or Feat: with a capital, is the most common reason a change is left out of a release, so check the first word of each message.
Step 3 · Install semantic-release and write the config
Install semantic-release and the two plugins it does not include, pinned to exact versions so a new release cannot change behaviour without a commit in your history:
npm install --save-dev --save-exact semantic-release@26.0.1 @semantic-release/changelog@7.0.0 @semantic-release/git@11.0.1The first install downloads about 75 MB into node_modules. If you are on prepaid mobile data, do it once over Wi-Fi: npm keeps a cache in ~/.npm, so later installs of the same versions mostly come from disk, and on GitHub the runner's downloads do not touch your bundle at all.
Each part of a release is done by a plugin, run in the order you list them. Create release.config.js:
cat > release.config.js <<'JS'
// release.config.js
const plugins = [
// Read the commits since the last tag and pick patch, minor or major.
['@semantic-release/commit-analyzer', { preset: 'conventionalcommits' }],
// Turn the same commits into release notes.
['@semantic-release/release-notes-generator', { preset: 'conventionalcommits' }],
// Add those notes to the top of CHANGELOG.md.
['@semantic-release/changelog', { changelogFile: 'CHANGELOG.md' }],
// Write the new version into package.json, but do not publish to npm.
['@semantic-release/npm', { npmPublish: false }],
// Commit the changed files back to the branch.
[
'@semantic-release/git',
{
assets: ['CHANGELOG.md', 'package.json', 'package-lock.json'],
message: 'chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}',
},
],
]
// On your computer there is no GitHub token, so leave the GitHub plugin out
// when RELEASE_LOCAL is set. The workflow never sets it.
if (!process.env.RELEASE_LOCAL) {
plugins.push('@semantic-release/github')
}
module.exports = {
branches: ['main'],
plugins,
}
JSWhat each choice does:
preset: 'conventionalcommits'makes both the analyzer and the notes follow the Conventional Commits rules, includingfeat!:. Without it they use the older Angular convention. The preset ships with the analyzer, so there is nothing else to install.npmPublish: falsekeeps the version bump inpackage.jsonbut skipsnpm publish. Use this for apps, internal tools and anything that is not an npm package./tutorials/publish-an-npm-package-from-github-actions-with-provenancecovers turning publishing on.- The
gitplugin is what getsCHANGELOG.mdand the new version back into the repository. Without it the changelog file is written on the release machine and thrown away. The${nextRelease.version}placeholders are filled in by semantic-release, not by JavaScript, which is why the message sits in single quotes. @semantic-release/githubcreates the GitHub release with the notes, and comments on the issues and pull requests that went into it. It needs a token, which is why the config can leave it out on your machine.
Commit the setup. build: is a type that releases nothing:
git add .
git commit -m "build: release with semantic-release"Check it worked
Run a dry run with the full config. Outside a CI service semantic-release always runs as a dry run, but --dry-run makes that explicit. It stops at the GitHub plugin, because there is no token:
npx semantic-release --dry-run > full-dry-run.log 2>&1 || grep -o 'ENOGHTOKEN No GitHub token specified' full-dry-run.log
rm full-dry-run.logYou see ENOGHTOKEN No GitHub token specified. That is the check you want to fail here: in the workflow, GitHub supplies the token. Now run it without the GitHub plugin:
RELEASE_LOCAL=1 npx semantic-release --dry-run 2>&1 | grep -E 'Allowed to push|next release version'The output includes Allowed to push to the Git repository and There is no previous release, the next release version is 1.0.0. The very first release with a feat or fix in it is always 1.0.0.
Step 4 · Rehearse the first release
A dry run skips the steps that change things. To watch them, run a real release against the practice remote. --no-ci tells semantic-release to go ahead even though it is not running in CI. Only use it like this, on a throwaway repository:
RELEASE_LOCAL=1 npx semantic-release --no-ci 2>&1 | grep -E 'Created tag|published|Skip publishing'You see Created tag v1.0.0, Skip publishing to npm registry as npmPublish is false and Release 1.0.0 published on default channel. Nothing went to npm. "Published" here means the tag and the release commit were pushed.
Check it worked
git log --oneline -3
git tag
node -p "require('./package.json').version"
git --git-dir="$HOME/release-demo/origin.git" tagThe newest commit is chore(release): 1.0.0 [skip ci], made by the git plugin. git tag lists v1.0.0, package.json now says 1.0.0, and the practice remote has the tag too. CHANGELOG.md exists with a 1.0.0 section listing the greet feature.
Step 5 · See which version each commit produces
Now add commits one at a time and ask semantic-release what it would do after each. Start with documentation:
cat > README.md <<'MD'
# greet
Says hello. `greet('Amara')` returns `Hello, Amara`.
MD
git add README.md
git commit -m "docs: add a README"
RELEASE_LOCAL=1 npx semantic-release --dry-run 2>&1 | grep 'no relevant changes'It prints There are no relevant changes, so no new version is released. Documentation alone is not a release. Next, a bug fix: names with stray spaces were greeted as typed.
cat > index.js <<'JS'
function greet(name) {
return `Hello, ${name.trim()}`
}
module.exports = { greet }
JS
git commit -am "fix: trim spaces around the name"
RELEASE_LOCAL=1 npx semantic-release --dry-run 2>&1 | grep 'next release version is 1.0.1'A fix makes 1.0.1. Add a feature on top:
cat > index.js <<'JS'
function greet(name) {
return `Hello, ${name.trim()}`
}
function farewell(name) {
return `Goodbye, ${name.trim()}`
}
module.exports = { greet, farewell }
JS
git commit -am "feat: add a farewell function"
RELEASE_LOCAL=1 npx semantic-release --dry-run 2>&1 | grep 'next release version is 1.1.0'The fix and the feature are both unreleased, and the feature is bigger, so the answer becomes 1.1.0, not 1.0.2. Finally, change what greet returns. Anyone using it will have to change their code, so the commit says so in a footer. The second -m becomes the commit body, separated from the summary by a blank line, which is where footers go:
cat > index.js <<'JS'
function greet(name) {
return { text: `Hello, ${name.trim()}` }
}
function farewell(name) {
return `Goodbye, ${name.trim()}`
}
module.exports = { greet, farewell }
JS
git commit -a -m "feat: return an object from greet" -m "BREAKING CHANGE: greet now returns { text } instead of a string."
RELEASE_LOCAL=1 npx semantic-release --dry-run 2>&1 | grep 'next release version is 2.0.0'Check it worked
Each grep above printed its line: no release, then 1.0.1, 1.1.0 and 2.0.0. If a grep prints nothing, the dry run picked something else; run the command again without | grep … and read the lines from @semantic-release/commit-analyzer, which name the release type it gave each commit.
Step 6 · Release 2.0.0 and read the changelog
Run the rehearsal release again:
RELEASE_LOCAL=1 npx semantic-release --no-ci 2>&1 | grep -E 'Created tag|published'It reports Created tag v2.0.0 and Release 2.0.0 published on default channel.
Check it worked
head -n 16 CHANGELOG.md
git tag
node -p "require('./package.json').version"The top of CHANGELOG.md is a 2.0.0 section with three headings: ⚠ BREAKING CHANGES with the footer text, Features with both features, and Bug Fixes with the trim fix. The docs and build commits are not there. Below it is the 1.0.0 section from before. git tag lists v1.0.0 and v2.0.0, and package.json says 2.0.0.
The links in the changelog look odd, starting https:/ and a file path, because the remote is a folder. On GitHub they point to the compare view and to each commit.
Step 7 · Add the release workflow
On GitHub, the release runs in a workflow after each push to main. Create .github/workflows/release.yml:
mkdir -p .github/workflows
cat > .github/workflows/release.yml <<'YAML'
name: Release
on:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-node@v7
with:
node-version: 26
cache: npm
- run: npm ci
- run: npm audit signatures
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
YAMLWhat matters in it:
fetch-depth: 0fetches the whole history and every tag. By default checkout fetches one commit, and semantic-release would not find the last release tag or the commits since.- The workflow starts with read-only permissions and the release job asks for exactly what the plugins use:
contents: writeto push the tag and the release commit and create the GitHub release, andissues: writeandpull-requests: writefor the comments. If you later publish to npm with provenance, that job also needsid-token: write. concurrencywithcancel-in-progress: falsequeues a second push behind a running release instead of cancelling it halfway through tagging.GITHUB_TOKENis created by GitHub for each run, so no secret goes into the file.RELEASE_LOCALis not set, so the GitHub plugin runs.- On GitHub the CI variables are present, so semantic-release does a real release with no flags. A push whose commits are all
docs:orchore:runs the job and releases nothing. npm audit signatureschecks that the packagesnpm ciinstalled carry valid registry signatures before code from them runs with write access to your repository.
In a project with tests, put them in a separate job and give the release job needs: test, so a red build never releases. /tutorials/run-node-tests-in-github-actions builds that job.
Check it worked
Check the file with actionlint (see /tutorials/github-actions-first-workflow for downloading it), then run the commands the job runs:
actionlint
echo "actionlint exit code: $?"
npm ci
npm audit signaturesactionlint prints nothing and the exit code is 0. npm ci installs from the lock file without changing it, and npm audit signatures reports a count of packages with verified registry signatures and attestations, and exits with 0.
Step 8 · Move it to your GitHub repository
The tags in ~/release-demo belong to the practice remote, so do not push this demo to a real repository. In your own project, copy over three things: the dev dependencies (the same npm install command), release.config.js and .github/workflows/release.yml. Commit them with a message such as build: release with semantic-release and push:
git add package.json package-lock.json release.config.js .github/workflows/release.yml
git commit -m "build: release with semantic-release"
git push origin mainThen open the Actions tab and the Release run. The log shows the same lines you saw locally: the last release it found, the analysis of each commit and the next version. If the project already has tags in the form v1.4.2, semantic-release continues from the highest one. If it has none, the first release is 1.0.0. After a release, the Releases page shows the new version with the notes, and each issue or pull request named in those commits gets a comment.
Two problems you may meet:
- The job fails while pushing the release commit with a message about protected branches. The built-in
GITHUB_TOKENcannot push past branch protection onmain. Either remove the@semantic-release/gitplugin (the notes still appear on the Releases page, butCHANGELOG.mdand the version inpackage.jsonare no longer updated in the repository), or have the job create a GitHub App token withactions/create-github-app-tokenand use that, as the semantic-release GitHub Actions recipe describes. Avoid a personal access token: it carries your own permissions and works anywhere if it leaks. - The log says there are no relevant changes when you expected a release. Read the commit messages since the last tag with
git log --oneline $(git describe --tags --abbrev=0)..HEADand look for a missing or misspelt type. Squash merges use the pull request title as the commit message, so with that merge style the title must follow the format too.
semantic-release or release-please
release-please, from Google, reads the same Conventional Commits but works differently. Instead of releasing on every qualifying push, it opens a release pull request and keeps it updated with the next version and changelog. Nothing is released until someone merges that pull request. That suits teams that want a person to choose the moment, and repositories where main is protected. semantic-release suits projects that want every merged fix out straight away with no extra step. Both need the commit discipline from Step 2, so the habit carries over if you switch.
Check it worked
On GitHub, the first run after your push shows either a new release on the Releases page, or the line There are no relevant changes, so no new version is released. if the commits since the last tag were only build: and similar. Either is correct. Push a fix: commit and confirm the next run creates a patch release.
When you are finished with the practice project, delete it. This removes the demo project and its practice remote, nothing else:
rm -rf ~/release-demoNext steps
- Publish the package to npm from the same kind of workflow, with provenance:
/tutorials/publish-an-npm-package-from-github-actions-with-provenance. - Run tests before the release job:
/tutorials/run-node-tests-in-github-actions. - See the decisions semantic-release automates, done by hand with tags and a changelog:
/tutorials/version-releases-with-semantic-versioning-and-a-changelog. - Brush up on commits and history:
/tutorials/make-your-first-git-commits.
Related tutorials
- Run only the CI jobs a change needs with path filters and concurrencyYou will have GitHub Actions workflows that skip tests for documentation-only changes without blocking merges, cancel superseded pull request runs, queue deploys instead of cancelling them, and stop any job that runs too long.
- Run Python tests and linters in GitHub Actions with uvYou will have a GitHub Actions workflow that installs a Python project with uv from its lock file, fails on a stale uv.lock, runs Ruff and pytest with a coverage floor on two Python versions, caches uv's downloads and keeps the coverage report as an artifact.
- Publish an npm package from GitHub Actions with trusted publishing and provenanceYou will have a small npm package that GitHub Actions publishes on each version tag through npm trusted publishing, with no NPM_TOKEN secret and a provenance attestation on every release.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials