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_requestevents 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
editedso a fixed title clears the check. - Latchkey runs the lint check on cheaper runners that retry transient failures.
Related guides
How to Auto-Update a Changelog in GitHub ActionsAutomatically generate and commit changelog entries in GitHub Actions from conventional commits, so CHANGELOG…
How to Fail the Build on a Coverage Drop in GitHub ActionsFail a GitHub Actions build when test coverage falls below a threshold, parsing the coverage percentage from…