Skip to content

Action — check-commit-msg ​

Validates commit messages against Conventional Commits 1.0.0 with the type set release-please understands. The same script backs the prek / pre-commit commit-msg hook, so local commits and CI apply identical rules.

Usage ​

yaml
steps:
  - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
    with:
      fetch-depth: 0 # the range must be in the local history

  # The commits of the push or pull request, also on a new or force-pushed branch.
  - id: base
    uses: KevinDeBenedetti/github-workflows/.github/actions/change-base@v0.57.0 # x-release-please-version
  - if: steps.base.outputs.mode != 'none'
    uses: KevinDeBenedetti/github-workflows/.github/actions/check-commit-msg@v0.57.0 # x-release-please-version
    with:
      range: ${{ steps.base.outputs.base }}..HEAD

change-base finds where the change starts. Any other range works too, e.g. ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}.

As a hook in another repo's prek.toml (needs the commit-msg hook type):

toml
default_install_hook_types = ["pre-commit", "commit-msg"]

[[repos]]
repo = "https://github.com/KevinDeBenedetti/github-workflows"
rev = "vX.Y.Z"
hooks = [{ id = "check-commit-msg" }]

Inputs ​

InputDefaultDescription
range—Git revision range to check, e.g. <base>..<head> (required)

Rules ​

  • Header <type>(<optional scope>)<optional !>: <summary>, with <type> one of feat, fix, perf, revert, deps, docs, style, chore, test, build, ci.
  • refactor is rejected (house rule: use chore for a refactor with no user-facing effect — release-please would hide it like chore anyway).
  • Header at most 100 characters (commitlint's header-max-length default); a body, when present, starts after one blank line.
  • Breaking changes use ! before the colon; a BREAKING CHANGE: footer is optional, as in the spec.

Notes ​

  • Dual-mode: with file arguments it checks those message files (prek passes the commit message file); otherwise it checks every non-merge commit of $COMMIT_RANGE.
  • Merge …, fixup! …, squash! … and amend! … messages generated by git are let through; # comment lines from the editor buffer are ignored.
  • Fails (exit 1) listing each offending commit and what is wrong with it.
  • Fails (exit 2) when git cannot read the range, e.g. an end outside a shallow clone, rather than passing with no commit checked.