Semantic Releases With Github Actions

1 min read 140 words

If you stick to Conventional Commits for your commit messages, you can create tags and releases with GitHub Actions for every code change you push to a repository. This is great for automated and continuous releases!

Create a file in .github/workflows to store the configuration:

name: Version

on:
  push:
    branches: ["main"]

jobs:
  version:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Semantic Release
        uses: cycjimmy/semantic-release-action@v2
        id: semantic
        with:
          extra_plugins: |
            @semantic-release/git
            @semantic-release/changelog
        env:
          GITHUB_TOKEN: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Using Semantic Versioning, every push to the main branch can trigger a new version with Conventional Commits. Additionally, you need a .releaserc file:

{
  "branches": ["main"]
}

On every run, all commit messages since the last tagged version from the configured branch will be parsed to generate a new release if needed.