How to Automate the Version Bump Before Publishing
Let semantic-release derive the next version from conventional commits, or bump manually with npm version, so the tag and manifest version stay in sync.
Automated versioning removes manual edits. semantic-release analyzes commit messages, computes the next version, updates the changelog, tags, and publishes. A lighter option runs npm version from CI to bump and tag. Both keep the manifest and Git tag aligned.
Steps
- Adopt a commit convention semantic-release understands (for example Conventional Commits).
- Run
semantic-releaseon the default branch with the registry token available. - It bumps, tags, publishes, and creates the GitHub release in one step.
Workflow
.github/workflows/ci.yml
permissions:
contents: write
id-token: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}Manual bump alternative
Terminal
npm version patch -m "chore(release): %s"
git push --follow-tagsGotchas
- semantic-release needs full git history; set
fetch-depth: 0on checkout. - It refuses to publish if the commits since the last tag imply no release.
Related guides
How to Publish a Monorepo With ChangesetsPublish only the changed packages in a monorepo from CI with changesets, lerna, or nx release, versioning and…
How to Publish Only on a Tag or ReleaseGate a publish job to run only on a Git tag or GitHub release event, so packages never ship from an in-progre…
How to Prevent Publishing a Duplicate VersionStop CI from failing on a duplicate publish by checking whether the version already exists first, or using a…