Skip to content

Commit 2ca7070

Browse files
committed
ci: check the title, and stop checking messages that get discarded
main is linear and every subject ends in (#N): this repository squashes, so the commits on a branch never reach it. The title becomes the subject. Checking each commit was protecting history that does not exist, and cost thirty lines of shell to do it. What is left is two commands. The bare 'commit-check --message' still cannot be one of them -- it reads HEAD, the synthetic merge commit, which the engine skips and would pass having read nothing -- so the title goes in through stdin instead, which sidesteps HEAD entirely and needs no enumeration. Contributors lose CI feedback on intermediate commit messages. The pre-commit hook is where that belongs anyway: it arrives while the message is being written rather than a round trip later. Verified on a merge ref: bad title 1, good title 0, good title with a bad branch name 1.
1 parent 0d37026 commit 2ca7070

1 file changed

Lines changed: 14 additions & 41 deletions

File tree

‎.github/workflows/commit-check.yml‎

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,51 +44,24 @@ jobs:
4444
- name: Install commit-check from this checkout
4545
run: python -m pip install .
4646

47-
- name: Check the commits, the title, the branch and the author
47+
- name: Check the title, the branch and the author
4848
env:
4949
# Via the environment, never interpolated into the script: a pull
5050
# request title is attacker-controlled text.
5151
PR_TITLE: ${{ github.event.pull_request.title }}
5252
run: |
53-
# `commit-check --message` on its own inspects HEAD, and on a
54-
# pull_request checkout HEAD is the synthetic merge commit — which
55-
# the engine skips, so the whole check would pass having validated
56-
# nothing. Enumerate the real commits instead: HEAD^1 is the base
57-
# tip, HEAD^2 is the branch tip, so HEAD^1..HEAD^2 is this PR.
58-
if ! git rev-parse -q --verify 'HEAD^2' > /dev/null; then
59-
echo "::error::HEAD is not a merge commit, so the pull request's" \
60-
"commits cannot be enumerated. Refusing to report a pass" \
61-
"without checking anything."
62-
exit 1
63-
fi
64-
65-
status=0
66-
67-
count=$(git rev-list --count 'HEAD^1..HEAD^2')
68-
echo "::group::Commit messages ($count)"
69-
index=0
70-
while IFS= read -r -d '' message; do
71-
index=$((index + 1))
72-
echo "--- commit $index/$count"
73-
printf '%s' "$message" | commit-check --message --no-banner || status=1
74-
done < <(git log --pretty=format:'%B%x00' --reverse 'HEAD^1..HEAD^2')
75-
echo "::endgroup::"
76-
77-
# The subject a squash merge will actually commit.
78-
echo "::group::Pull request title"
79-
printf '%s\n' "$PR_TITLE" | commit-check --message --no-banner || status=1
80-
echo "::endgroup::"
81-
82-
# --branch resolves GITHUB_HEAD_REF when the checkout is detached,
83-
# so these need no extra context.
53+
# The title, because a squash merge commits it as the subject. The
54+
# branch's own commit messages are not checked: this repository
55+
# squashes, so they never reach main. A local hook is where that
56+
# feedback belongs — it arrives while the message is being written,
57+
# not a CI round trip later.
8458
#
85-
# stdin is closed explicitly. Left open, commit-check blocks waiting
86-
# to read a message even for checks that do not take one — verified
87-
# by hand, it hangs until killed. These checks therefore see the
88-
# author of HEAD, which is what commit-check-action reports today.
89-
echo "::group::Branch and author"
90-
commit-check --branch --author-name --author-email --no-banner \
91-
< /dev/null || status=1
92-
echo "::endgroup::"
59+
# Not a bare `commit-check --message` either. That reads HEAD, which
60+
# on a pull_request checkout is the synthetic merge commit, which the
61+
# engine skips — so it would report a pass having read nothing.
62+
printf '%s\n' "$PR_TITLE" | commit-check --message --no-banner
9363
94-
exit "$status"
64+
# stdin closed: left open, commit-check waits to read a message even
65+
# for checks that do not take one, and the step hangs rather than
66+
# fails. --branch resolves GITHUB_HEAD_REF on a detached checkout.
67+
commit-check --branch --author-name --author-email --no-banner < /dev/null

0 commit comments

Comments
 (0)