Skip to content
Latchkey

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 (or release field) listing the plugins you want.
  • Trigger the workflow on push to main.
  • Grant contents: write and issues: write to the job.
  • Run npx semantic-release with GITHUB_TOKEN in 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: 0 so 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

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