ci: public-text check: header-like added lines, backslash paths, unreadable inputs

An added line that begins with '++ ' is an added line, not a diff header;
the share path is matched with either slash; a missing title or
description file, an unknown commit or a failing grep is an error (exit 2),
never 'clean'. Controls for each in the self-test; each fails on the
previous script.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Fable 5.2 committed 2026-11-22 06:32:48 -08:00
1 parent abff195976
commit eba1949fb1
2 files changed
+28 -8

No files matched your search

+12
View File
@@ -29,4 +29,16 @@ echo "results under $nas" > body; expect 1 "share path in the description" "$mb"
echo "an old line with $seat" >> a.txt; git commit -q -am "old"; mb2=$(git rev-parse HEAD)
echo "new clean line" >> a.txt; git commit -q -am "new"
expect 0 "an existing line is not this change's" "$mb2" HEAD title body
# A file line that begins with "++ " shows in the diff as "+++ ...": an added line, not a header.
printf '%s
' "++ $seat" >> a.txt; git commit -q -am "plus line"
expect 1 "an added line that looks like a diff header" "$mb2" HEAD title body
git reset -q --hard HEAD~1
bs=$(printf '\')
printf '%s
' "${bs}${bs}nas${bs}sha""re${bs}rd""ma${bs}z" > title
expect 1 "backslash form of the share path in the title" "$mb2" HEAD title body; : > title
expect 2 "a missing title file is an error, not clean" "$mb2" HEAD no-such-title body
expect 2 "a missing description file is an error, not clean" "$mb2" HEAD title no-such-body
expect 2 "an unknown commit is an error, not clean" 0000000000000000000000000000000000000000 HEAD title body
echo "public-text-check-test: ok"
+16 -8
View File
@@ -11,7 +11,14 @@
set -euo pipefail
[ "$#" -eq 4 ] || { echo "usage: public-text-check.sh MERGE_BASE HEAD TITLE_FILE BODY_FILE" >&2; exit 2; }
mb=$1; head=$2; title=$3; body=$4
pat='(claude|codex)0[0-9]|share/rdma|V:[/\]share|diskstation'
for f in "$title" "$body"; do
[ -f "$f" ] && [ -r "$f" ] || { echo "public-text: cannot read $f" >&2; exit 2; }
done
git rev-parse -q --verify "$mb^{commit}" >/dev/null && git rev-parse -q --verify "$head^{commit}" >/dev/null ||
{ echo "public-text: unknown commit $mb or $head" >&2; exit 2; }
# match: a grep error fails the check instead of reading as "no hit".
match() { local rc=0; grep -E -i -- "$pat" "$@" || rc=$?; [ "$rc" -le 1 ] || { echo "public-text: grep failed ($rc)" >&2; exit 2; }; }
pat='(claude|codex)0[0-9]|share[/\]rdma|V:[/\]share|diskstation'
out=$(mktemp); trap 'rm -f "$out"' EXIT
report() { # report WHERE < matching lines
local where=$1 line
@@ -24,14 +31,15 @@ report() { # report WHERE < matching lines
git diff --no-color --no-renames -U0 "$mb" "$head" -- . \
':(exclude).github/scripts/public-text-check.sh' ':(exclude).github/scripts/public-text-check-test.sh' |
awk '
/^\+\+\+ / { f = substr($0, 7); next }
/^@@ / { split($3, a, ","); n = substr(a[1], 2) + 0; next }
/^\+/ { print f ":" n ": " substr($0, 2); n++ }
' | { grep -E -i -- "$pat" || true; } | report "added line"
/^diff --git / { hdr = 1; next }
hdr && /^\+\+\+ / { f = substr($0, 7); next }
/^@@ / { hdr = 0; split($3, a, ","); n = substr(a[1], 2) + 0; next }
!hdr && /^\+/ { print f ":" n ": " substr($0, 2); n++ }
' | match | report "added line"
# Commit messages (subjects and bodies) of the pull request.
git log --format='%h %s%n%b' "$mb..$head" | { grep -E -i -- "$pat" || true; } | report "commit message"
{ grep -E -i -- "$pat" "$title" || true; } | report "title"
{ grep -E -i -- "$pat" "$body" || true; } | report "description"
git log --format='%h %s%n%b' "$mb..$head" | match | report "commit message"
match "$title" | report "title"
match "$body" | report "description"
hits=$(wc -l <"$out" | tr -d ' ')
if [ "$hits" -gt 0 ]; then
cat "$out"