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
| Input | Default | Description |
|---|---|---|
range | — | Git revision range to check, e.g. <base>..<head> (required) |
Rules
- Header
<type>(<optional scope>)<optional !>: <summary>, with<type>one offeat,fix,perf,revert,deps,docs,style,chore,test,build,ci. refactoris rejected (house rule: usechorefor a refactor with no user-facing effect — release-please would hide it likechoreanyway).- Header at most 100 characters (commitlint's
header-max-lengthdefault); a body, when present, starts after one blank line. - Breaking changes use
!before the colon; aBREAKING 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! …andamend! …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.