Skip to content
Latchkey

How to Enforce Conventional Commits in CI in GitHub Actions

Tools that derive versions and changelogs from commits only work if the commits follow the convention; enforce it in CI.

Lint the PR title (or commits) against the Conventional Commits spec so a non-conforming PR fails the check.

Steps

  • Trigger on pull_request events that change the title or commits.
  • Run a conventional-commit linter on the PR title.
  • Grant pull-requests: read.
  • Make the check required in branch protection.

Workflow

.github/workflows/pr-title.yml
on:
  pull_request:
    types: [opened, edited, synchronize]
permissions:
  pull-requests: read
jobs:
  lint-title:
    runs-on: ubuntu-latest
    steps:
      - uses: amannn/action-semantic-pull-request@v5
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Gotchas

  • Linting the PR title is simplest when you squash-merge; lint commits if you merge them individually.
  • Re-run on edited so a fixed title clears the check.
  • Latchkey runs the lint check on cheaper runners that retry transient failures.

Related guides

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