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@v7
    with:
      fetch-depth: 0 # the range must be in the local history

  - uses: KevinDeBenedetti/github-workflows/.github/actions/check-commit-msg@main
    with:
      range: ${{ 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.