igneum/tools/amd-prove/check-job-bash.sh

26 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Checks the bash body embedded in a PowerShell job script (the here-string assigned to $bash) with `bash -n`
# before it is published. The class of 5 October 2026 (job cpu-prove-pc1-small): an apostrophe inside a single-quoted
# awk program ended the quote, bash refused the whole for-loop, and the job reported exit 0 with no measurement.
# Usage: tools/amd-prove/check-job-bash.sh <job.ps1>... (exit 1 when a body does not parse)
set -uo pipefail
rc=0
tmp="$(mktemp)"
for f in "$@"; do
python3 - "$f" > "$tmp" <<'PY'
import re,sys
t=open(sys.argv[1],encoding='utf-8').read()
m=re.search(r'^\$bash = @"\n(.*?)\n"@', t, re.S|re.M)
if not m: print("NO-HERE-STRING"); sys.exit(0)
b=m.group(1)
bt=chr(96)
# PowerShell expands $NAME and $(...) in a double-quoted here-string; a backtick-dollar is a literal dollar.
for v in ('pkgW','jobW','FIXTURES'): b=b.replace('$'+v, 'PLACEHOLDER_'+v)
b=b.replace(bt+'$','$').replace(bt+bt,bt)
print(b)
PY
if grep -q '^NO-HERE-STRING$' "$tmp"; then echo "$f: no bash here-string, skipped"; continue; fi
if bash -n "$tmp" 2>"$tmp.err"; then echo "$f: bash body parses"; else echo "$f: BASH BODY DOES NOT PARSE"; cat "$tmp.err"; rc=1; fi
done
rm -f "$tmp" "$tmp.err"
exit $rc