How to Automate Releases With semantic-release in GitHub Actions
semantic-release reads your Conventional Commit history, computes the next semver version, then tags, releases, and updates the changelog with no manual version edits.
Run npx semantic-release from a workflow on pushes to your release branch. Grant contents: write and issues: write, and provide GITHUB_TOKEN (plus NPM_TOKEN if you publish to npm).
Steps
- Add a
.releaserc(orreleasefield) listing the plugins you want. - Trigger the workflow on
pushtomain. - Grant
contents: writeandissues: writeto the job. - Run
npx semantic-releasewithGITHUB_TOKENin the environment.
Workflow
.github/workflows/release.yml
on:
push:
branches: [main]
permissions:
contents: write
issues: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm ci
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}Gotchas
- Use
fetch-depth: 0so semantic-release can read the full tag and commit history. - semantic-release decides nothing if no commit since the last release is a
feat/fix/breaking change.
Related guides
How to Create a GitHub Release on Tag Push in GitHub ActionsCreate a GitHub Release automatically when you push a version tag using softprops/action-gh-release, with aut…
How to Enforce Conventional Commits With commitlint in GitHub ActionsValidate commit messages against the Conventional Commits spec in GitHub Actions with wagoid/commitlint-githu…