chore(gate): check.sh can list its lanes and run one of them
--list prints the lane names, --only "<lane>" runs that one lane, so a runner can schedule the lanes itself and a red lane can be re-run on its own. An --only run reports that lane, never the gate, and an unknown name exits 2 instead of passing with nothing run; the contract test holds both.
This commit is contained in:
@@ -1299,16 +1299,24 @@
|
||||
"cd \"$(dirname \"$0\")/..\" || exit 2",
|
||||
"mode=all",
|
||||
"brief=0",
|
||||
"for arg in \"$@\"; do",
|
||||
" case \"$arg\" in",
|
||||
" all | lint) mode=\"$arg\" ;;",
|
||||
"list=0",
|
||||
"only=\"\"",
|
||||
"usage() { echo 'usage: scripts/check.sh [lint] [--brief] [--list | --only \"<lane>\"]' >&2; exit 2; }",
|
||||
"while [ $# -gt 0 ]; do",
|
||||
" case \"$1\" in",
|
||||
" all | lint) mode=\"$1\" ;;",
|
||||
" --brief) brief=1 ;;",
|
||||
" --list) list=1 ;;",
|
||||
" --only) [ $# -ge 2 ] || usage; only=\"$2\"; shift ;;",
|
||||
" esac",
|
||||
" shift",
|
||||
"done",
|
||||
"[ \"$list\" = 1 ] && [ -n \"$only\" ] && usage",
|
||||
"export MSYS_NO_PATHCONV=1 # Git Bash: do not rewrite the in-container paths below",
|
||||
"TESTCOMPOSE=backend/docker-compose.test.yml",
|
||||
"failed=()",
|
||||
"timings=()",
|
||||
"ran=0",
|
||||
"ms() { date +%s%3N; }",
|
||||
"secs() { awk -v t=\"$1\" 'BEGIN { printf \"%.1f\", t / 1000 }'; }",
|
||||
"took=\"\"",
|
||||
@@ -1316,7 +1324,7 @@
|
||||
" took=\"$(secs $(($(ms) - $3)))\"",
|
||||
" timings+=(\"$(printf '%8s s %s' \"$took\" \"$1\")$([ \"$2\" = red ] && echo ' (red)')\")",
|
||||
" if [ -n \"${GATE_TIMES_FILE:-}\" ]; then",
|
||||
" printf '%s\\t%s\\t%s\\t%s\\t%s\\t%s\\n' \"$(date -u +%FT%TZ)\" \"$mode\" \"$1\" \"$took\" \"$2\" \\",
|
||||
" printf '%s\\t%s\\t%s\\t%s\\t%s\\t%s\\n' \"$(date -u +%FT%TZ)\" \"${only:+only}${only:-$mode}\" \"$1\" \"$took\" \"$2\" \\",
|
||||
" \"$(git rev-parse --short 'HEAD^{tree}' 2>/dev/null)\" >>\"$GATE_TIMES_FILE\"",
|
||||
" fi",
|
||||
" return 0",
|
||||
@@ -1324,6 +1332,9 @@
|
||||
"lane() { # lane <name> <command…> — run it, remember a failure, never stop",
|
||||
" local name=\"$1\" t0 result=ok",
|
||||
" shift",
|
||||
" if [ \"$list\" = 1 ]; then echo \"$name\"; return 0; fi",
|
||||
" [ -n \"$only\" ] && [ \"$name\" != \"$only\" ] && return 0",
|
||||
" ran=$((ran + 1))",
|
||||
" t0=\"$(ms)\"",
|
||||
" if [ \"$brief\" = 0 ]; then",
|
||||
" echo \">> $name…\"",
|
||||
@@ -1407,14 +1418,21 @@
|
||||
" lane \"pip-audit (backend lock)\" pip_audit",
|
||||
" lane \"npm audit (production dependencies)\" frontend npm audit --omit=dev --audit-level=high",
|
||||
"fi",
|
||||
"[ \"$list\" = 1 ] && exit 0",
|
||||
"if [ -n \"$only\" ] && [ \"$ran\" = 0 ]; then",
|
||||
" echo \"no lane named '$only' in mode $mode — see: scripts/check.sh $mode --list\" >&2",
|
||||
" exit 2",
|
||||
"fi",
|
||||
"scope=\"gate ($mode)\"",
|
||||
"[ -n \"$only\" ] && scope=\"lane '$only' only (not the gate)\"",
|
||||
"echo \">> lane times:\"",
|
||||
"printf '%s\\n' \"${timings[@]}\"",
|
||||
"echo \"$(printf '%8s' \"$(secs $(($(ms) - gate_t0)))\") s total\"",
|
||||
"if [ ${#failed[@]} -eq 0 ]; then",
|
||||
" echo \">> gate ($mode): green ✓\"",
|
||||
" echo \">> $scope: green ✓\"",
|
||||
" exit 0",
|
||||
"fi",
|
||||
"echo \">> gate ($mode): RED — ${failed[*]}\" >&2",
|
||||
"echo \">> $scope: RED — ${failed[*]}\" >&2",
|
||||
"exit 1"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user