Skip to content

Commit 9a77bf4

Browse files
ci: simplify no-Cyrillic gate base resolution (WP-415)
A new-branch push event has before=0000..., and the earlier fallback to the repo's root commit diffed the entire history -- catching every pre-existing Cyrillic file instead of just this push's own change. Always diff against the pushed commit's own parent. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 64f89b8 commit 9a77bf4

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

‎.github/workflows/no-cyrillic-gate.yml‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,20 @@ jobs:
1414

1515
- name: Resolve diff range
1616
id: range
17+
# pull_request has a well-defined base/head. For push, the event's
18+
# "before" is unusable as a base: it is all-zero on a new branch
19+
# (falling back to the repo's root commit would diff the entire
20+
# history, catching every pre-existing Cyrillic file) and can point
21+
# at a commit this fetch no longer has after a force-push/amend
22+
# (git diff/log would fail with "bad object"). The new commit's own
23+
# parent answers "what did this push actually add" in every case.
1724
run: |
1825
if [ "${{ github.event_name }}" = "pull_request" ]; then
1926
base="${{ github.event.pull_request.base.sha }}"
2027
head="${{ github.event.pull_request.head.sha }}"
2128
else
22-
base="${{ github.event.before }}"
2329
head="${{ github.event.after }}"
24-
case "$base" in
25-
""|0000000000000000000000000000000000000000)
26-
base="$(git rev-list --max-parents=0 "$head" | tail -1)" ;;
27-
esac
28-
# A force-push (amend/rebase) rewrites history, so "before" can
29-
# point at a commit this fetch no longer has -- git diff/log would
30-
# fail with "bad object" instead of reporting the real change.
31-
# Fall back to the new commit's own parent, which still answers
32-
# "what did this push actually add" after the rewrite.
33-
if ! git cat-file -e "${base}^{commit}" 2>/dev/null; then
34-
base="$(git rev-parse "${head}^" 2>/dev/null || git rev-list --max-parents=0 "$head" | tail -1)"
35-
fi
30+
base="$(git rev-parse -q --verify "${head}^" || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904)"
3631
fi
3732
echo "base=$base" >> "$GITHUB_OUTPUT"
3833
echo "head=$head" >> "$GITHUB_OUTPUT"
@@ -55,10 +50,12 @@ jobs:
5550
echo 'PASS: no new Cyrillic introduced.'
5651
5752
- name: Cyrillic gate — commit messages
53+
# Checks only the pushed commit's own message, not a base..head range:
54+
# base can be the empty-tree sentinel (a tree, not a commit), which a
55+
# commit range cannot use.
5856
run: |
59-
base="${{ steps.range.outputs.base }}"
6057
head="${{ steps.range.outputs.head }}"
61-
messages="$(git log "$base..$head" --format=%B)"
58+
messages="$(git log -1 --format=%B "$head")"
6259
if printf '%s' "$messages" | grep -qP '[\x{0400}-\x{04FF}\x{0500}-\x{052F}]'; then
6360
echo '::error::Commit message contains Cyrillic -- this repository is English-only going forward.'
6461
exit 1

0 commit comments

Comments
 (0)