Skip to content

Commit 845b8bf

Browse files
ci: replace strict Conventional Commits PR-title check with sanity check (#50)
The previous pr_title.yml workflow used amannn/action-semantic-pull-request@v5 to enforce strict Conventional Commits format on every PR title (feat:, fix:, etc.) plus a lowercase-subject regex. That conflicted with the project's actual title convention ("Add Wxxx rule-name (description)", "Fix Snnn false negatives ...") and so the validate check went red on every merged PR (e.g. #46, #47, #48, #49). Branch protection does not require this check, so the merge button stayed enabled and the failures shipped silently in the merged commits' status timelines. Replacing the strict format enforcer with a small inline shell script that catches the actual problems we have hit in practice: 1. Empty / whitespace-only titles -- noticeable in `gh pr list`. 2. Auto-generated branch-name titles (e.g. "Feat/w024-select-distinct -suspicious") that GitHub picks when an async PR-template render wipes out a freshly typed title. Matches a regex of the form ^[A-Z][a-z]+/[a-z0-9-] which catches the real cases without touching anything that looks like a sentence. 3. Titles longer than 100 characters, which truncate badly in the UI. Project titles like "Add W024 select-distinct-suspicious (...)" pass the sanity check; titles like "Feat/foo-bar" fail. Verified the regex matrix locally before committing. To restore stricter enforcement later, swap the inline script back for amannn/action-semantic-pull-request@v5 and adjust the project title convention to start with feat: / fix: prefixes.
1 parent bb3fbd5 commit 845b8bf

1 file changed

Lines changed: 50 additions & 21 deletions

File tree

.github/workflows/pr_title.yml

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
name: Validate PR title
22

3+
# Lightweight sanity check on PR titles. The previous version of this
4+
# workflow enforced strict Conventional Commits format ("feat: ...",
5+
# "fix: ..."), but that conflicted with the project's actual title style
6+
# ("Add Wxxx rule-name (description)", "Fix Snnn false negatives ...")
7+
# and so failed silently on every merged PR. This rewrite drops the
8+
# Conventional Commits check and instead catches the real problems:
9+
#
10+
# 1. Empty / whitespace-only titles.
11+
# 2. Auto-generated branch-name titles ("Feat/foo-bar", "Wip/x"),
12+
# which GitHub picks when the human types is wiped out by an async
13+
# template load. These titles are ugly in `git log` and merge
14+
# commit messages.
15+
# 3. Excessive length: anything over 100 chars truncates badly in
16+
# GitHub UIs and `gh pr list`.
17+
#
18+
# To enforce a stricter style later, restore the
19+
# amannn/action-semantic-pull-request@v5 action and update PR titles
20+
# accordingly.
21+
322
on:
423
pull_request_target:
524
types: [opened, edited, synchronize, reopened]
@@ -11,25 +30,35 @@ jobs:
1130
validate:
1231
runs-on: ubuntu-latest
1332
steps:
14-
- name: Check conventional commit prefix
15-
uses: amannn/action-semantic-pull-request@v5
33+
- name: Sanity-check PR title
1634
env:
17-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18-
with:
19-
types: |
20-
feat
21-
fix
22-
docs
23-
chore
24-
ci
25-
test
26-
style
27-
refactor
28-
perf
29-
build
30-
requireScope: false
31-
subjectPattern: ^(?![A-Z]).+$
32-
subjectPatternError: |
33-
PR title subject should start lowercase. E.g. "fix: catch UNION in
34-
W008" rather than "fix: Catch UNION in W008".
35-
validateSingleCommit: false
35+
PR_TITLE: ${{ github.event.pull_request.title }}
36+
run: |
37+
set -euo pipefail
38+
title="${PR_TITLE}"
39+
echo "PR title: ${title}"
40+
41+
# 1. Reject empty / whitespace-only titles.
42+
trimmed=$(echo -n "${title}" | tr -d '[:space:]')
43+
if [ -z "${trimmed}" ]; then
44+
echo "::error::PR title is empty or whitespace only."
45+
exit 1
46+
fi
47+
48+
# 2. Reject GitHub's auto-generated branch-name titles. These
49+
# look like 'Feat/foo-bar', 'Wip/x', 'Chore/y' (capitalised
50+
# branch prefix followed by a slash) and happen when the
51+
# PR template overwrites a freshly-typed title async.
52+
if echo "${title}" | grep -Eq '^[A-Z][a-z]+/[a-z0-9-]'; then
53+
echo "::error::PR title looks auto-generated from a branch name (e.g. 'Feat/foo-bar'). Please replace it with a descriptive human title."
54+
exit 1
55+
fi
56+
57+
# 3. Reject titles longer than 100 chars (truncates in UIs).
58+
length=${#title}
59+
if [ "${length}" -gt 100 ]; then
60+
echo "::error::PR title is ${length} characters; please shorten to 100 or fewer."
61+
exit 1
62+
fi
63+
64+
echo "PR title passes basic sanity checks."

0 commit comments

Comments
 (0)