Skip to content
Latchkey

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-release on 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-tags

Gotchas

  • semantic-release needs full git history; set fetch-depth: 0 on checkout.
  • It refuses to publish if the commits since the last tag imply no release.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →