diff --git a/seaweed-block/.github/scripts/public-text-check-test.sh b/seaweed-block/.github/scripts/public-text-check-test.sh new file mode 100755 index 0000000000..a59dc7e096 --- /dev/null +++ b/seaweed-block/.github/scripts/public-text-check-test.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Self-test of public-text-check.sh in a throwaway repository. +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd) +t=$(mktemp -d); trap 'rm -rf "$t"' EXIT +cd "$t"; git init -q .; git config user.email t@example.invalid; git config user.name t +echo base > a.txt; git add a.txt; git commit -q -m "base" +mb=$(git rev-parse HEAD) +: > title; : > body +run() { bash "$here/public-text-check.sh" "$@" >out 2>&1; } +expect() { # expect RC NAME + local want=$1 name=$2 rc=0 + shift 2 + run "$@" || rc=$? + [ "$rc" = "$want" ] || { echo "public-text-check-test: $name: exit $rc, want $want"; cat out; exit 1; } +} +echo "plain line" >> a.txt; git commit -q -am "add a plain line" +expect 0 "clean change" "$mb" HEAD title body +seat="clau""de06"; path="V:/sha""re/x"; nas="share/rd""ma/y" +echo "// asked by $seat" >> a.txt; git commit -q -am "comment" +expect 1 "seat name in an added line" "$mb" HEAD title body +grep -q "a.txt:3" out || { echo "public-text-check-test: hit does not name file and line"; cat out; exit 1; } +git reset -q --hard HEAD~1 +echo "ok" >> a.txt; git commit -q -am "review by $seat" +expect 1 "seat name in a commit subject" "$mb" HEAD title body +git reset -q --hard HEAD~1 +echo "see $path" > title; expect 1 "share path in the title" "$mb" HEAD title body; : > title +echo "results under $nas" > body; expect 1 "share path in the description" "$mb" HEAD title body; : > body +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 +# A grep that fails (exit 2) is an error: the check must refuse and never print "clean". +mkdir -p fakebin; printf '#!/bin/sh +exit 2 +' > fakebin/grep; chmod +x fakebin/grep +rc=0; PATH="$PWD/fakebin:$PATH" bash "$here/public-text-check.sh" "$mb2" HEAD title body >out 2>&1 || rc=$? +[ "$rc" = 2 ] || { echo "public-text-check-test: failing grep: exit $rc, want 2"; cat out; exit 1; } +if PATH=/usr/bin:/bin grep -q "clean" out; then echo "public-text-check-test: failing grep printed clean"; cat out; exit 1; fi +echo "public-text-check-test: ok" diff --git a/seaweed-block/.github/scripts/public-text-check.sh b/seaweed-block/.github/scripts/public-text-check.sh new file mode 100755 index 0000000000..3146d095c5 --- /dev/null +++ b/seaweed-block/.github/scripts/public-text-check.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# Refuses internal names in what a pull request makes public: the lines it +# adds, its commit messages, its title and its description. This repository is +# public; internal seat names and internal file-share paths do not belong in it. +# +# Usage: public-text-check.sh MERGE_BASE HEAD TITLE_FILE BODY_FILE +# Exit 0: clean. Exit 1: at least one hit (each printed). Exit 2: usage. +# +# The patterns live only here and in this check's own test; both files are +# excluded from the scan of added lines. +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 +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 + while IFS= read -r line; do + printf 'public-text: %s: %s +' "$where" "${line:0:160}" >>"$out" + done +} +# Added lines of the diff, with file and line number. +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 ' + /^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" | 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" + echo "public-text: $hits hit(s). Say what the code or test does instead of who asked for it; keep internal paths out." >&2 + exit 1 +fi +echo "public-text: clean" diff --git a/seaweed-block/.github/workflows/spec-trace.yml b/seaweed-block/.github/workflows/spec-trace.yml index 2e09b1c3cb..7bd9bdaa40 100644 --- a/seaweed-block/.github/workflows/spec-trace.yml +++ b/seaweed-block/.github/workflows/spec-trace.yml @@ -43,6 +43,7 @@ jobs: HEAD: ${{ github.event.pull_request.head.sha }} PR: ${{ github.event.pull_request.number }} BODY: ${{ github.event.pull_request.body }} + TITLE: ${{ github.event.pull_request.title }} run: | set -euo pipefail bash .github/scripts/spec-trace-check-test.sh @@ -60,3 +61,8 @@ jobs: done mkdir -p blobs bash .github/scripts/spec-trace-check.sh body.txt blobs title.txt + bash .github/scripts/public-text-check.sh "$mb" "$HEAD" title.txt body.txt