Skip to content

Commit 5a479fa

Browse files
committed
fix(release): invoke the new CI scripts via bash, and pin the exec-bit class
Completes the previous commit, which carried only the two mode changes because the call-site edits were not staged when it landed (--amend is denied in this repo, so this is additive rather than a rewrite). Call sites now go through `bash`, which is what most of this repo already does and which cannot break if a mode bit is lost to a patch application or a non-POSIX checkout: scripts/package-release.sh -> bash scripts/ci/check-binary-composition.sh .github/workflows/release.yml -> bash scripts/ci/append-vt-notes.sh With the 100755 modes from the previous commit, both sides are now correct, and either alone would have been sufficient. tests/test_script_exec_bit_contract.sh pins the class so it cannot recur: any tracked .sh whose COMMITTED mode is non-executable must not appear as the first word of a command in workflows, scripts, test-infrastructure or the Makefiles. The committed mode is the thing that matters and the thing no local run can check -- the working copy having the bit is exactly why this shipped. Verified in both directions: passes on this tree, and fails on the exact defect when the mode and the call site are reverted together. It joins backslash continuations before analysing, because its own first draft reported a false positive on ... && bash \ test-infrastructure/vm/vm-run-tests.sh --soak where the interpreter sits on the preceding line. A contract that cries wolf teaches people to ignore contracts, so that had to be right before it could be useful. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 359485b commit 5a479fa

3 files changed

Lines changed: 119 additions & 3 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ jobs:
249249
env:
250250
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
251251
VERSION: ${{ inputs.version }}
252-
run: scripts/ci/append-vt-notes.sh
252+
run: bash scripts/ci/append-vt-notes.sh
253253

254254
# ── 8. Publish package wrappers (npm + PyPI) ──────────────────
255255
# Wrappers in pkg/npm and pkg/pypi download the released binary at

‎scripts/package-release.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ if [ "$GOOS" = "windows" ]; then
172172
# Gate the artifact AFTER strip: strip is the last byte-changing step, so
173173
# this inspects exactly what goes into the archive. Runs here rather than in
174174
# a workflow step so the local artifact-flow smoke enforces the same thing.
175-
scripts/ci/check-binary-composition.sh --variant="$VARIANT" \
175+
bash scripts/ci/check-binary-composition.sh --variant="$VARIANT" \
176176
"$PACK_DIR/codebase-memory-mcp.exe" || exit 2
177177
cp LICENSE install.ps1 "$PACK_DIR/"
178178
scripts/gen-third-party-notices.sh "$PACK_DIR/THIRD_PARTY_NOTICES.md"
@@ -187,7 +187,7 @@ else
187187
[ -f "$BUILD_DIR/codebase-memory-mcp" ] ||
188188
{ echo "package-release: build first; missing $BUILD_DIR/codebase-memory-mcp" >&2; exit 2; }
189189
strip_release_binary "$BUILD_DIR/codebase-memory-mcp" || exit 2
190-
scripts/ci/check-binary-composition.sh --variant="$VARIANT" \
190+
bash scripts/ci/check-binary-composition.sh --variant="$VARIANT" \
191191
"$BUILD_DIR/codebase-memory-mcp" || exit 2
192192
cp LICENSE install.sh "$BUILD_DIR/"
193193
scripts/gen-third-party-notices.sh "$BUILD_DIR/THIRD_PARTY_NOTICES.md"
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env bash
2+
# Contract: a shell script invoked as a COMMAND must be executable in git.
3+
#
4+
# This exists because it cost a release build phase. scripts/ci/check-binary-
5+
# composition.sh was committed 100644 while being invoked directly from
6+
# scripts/package-release.sh, so every unix build leg died with:
7+
#
8+
# scripts/package-release.sh: line 190: .../check-binary-composition.sh: Permission denied
9+
#
10+
# It passed every local check because the WORKING COPY had the bit — only the
11+
# committed mode was wrong, which no amount of running it locally can reveal.
12+
# scripts/ci/append-vt-notes.sh had the identical defect queued up for the verify
13+
# step at the very end of the release.
14+
#
15+
# The rule is about the CALL SITE, not the file: `bash foo.sh` is equally correct
16+
# and mode-independent (and is what most of this repo does). What must not happen
17+
# again is a call site that needs the bit paired with a file that lacks it.
18+
#
19+
# Python, not shell: the analysis is "is this path the first word of a command",
20+
# and expressing that in `case` patterns is how the first version of this file
21+
# got a quoting bug of its own.
22+
set -euo pipefail
23+
24+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
25+
cd "$ROOT"
26+
27+
python3 - "$ROOT" <<'PY'
28+
import pathlib
29+
import re
30+
import subprocess
31+
import sys
32+
33+
root = pathlib.Path(sys.argv[1])
34+
35+
def git(*args):
36+
return subprocess.run(["git", "-C", str(root), *args],
37+
capture_output=True, text=True, check=True).stdout
38+
39+
# Tracked .sh files whose COMMITTED mode is non-executable.
40+
non_exec = set()
41+
for line in git("ls-files", "-s", "*.sh").splitlines():
42+
mode, _, _, path = line.split(maxsplit=3)
43+
if mode == "100644":
44+
non_exec.add(path)
45+
46+
# Places that actually execute things.
47+
search_roots = [root / ".github" / "workflows", root / "scripts",
48+
root / "test-infrastructure"]
49+
search_files = [root / "Makefile.cbm", root / "Makefile"]
50+
for base in search_roots:
51+
if base.is_dir():
52+
search_files += [p for p in base.rglob("*")
53+
if p.is_file() and p.suffix in {".yml", ".yaml", ".sh", ""}]
54+
55+
# Strip shell/YAML/Make prefixes that mean "not the first word of a command".
56+
INTERPRETED = re.compile(r"^(bash|sh|zsh|source|\.)\s")
57+
LEADERS = re.compile(r"^(?:[-@\t ]*)(?:run:\s*)?(?:then\s+|else\s+|do\s+|&&\s*|\|\|\s*|;\s*)*")
58+
59+
failures = []
60+
for path in search_files:
61+
try:
62+
text = path.read_text(errors="replace")
63+
except OSError:
64+
continue
65+
# Join backslash continuations into LOGICAL lines first. Without this,
66+
# ... && bash \
67+
# test-infrastructure/vm/vm-run-tests.sh --soak
68+
# reads as a bare script path at the start of a line and reports a false
69+
# positive — which is how the first draft of this contract flagged a call
70+
# site that was already correct.
71+
logical = []
72+
pending, start = "", 0
73+
for number, raw in enumerate(text.splitlines(), 1):
74+
if not pending:
75+
start = number
76+
stripped_end = raw.rstrip()
77+
if stripped_end.endswith("\\"):
78+
pending += stripped_end[:-1] + " "
79+
continue
80+
logical.append((start, pending + raw))
81+
pending = ""
82+
if pending:
83+
logical.append((start, pending))
84+
85+
for number, raw in logical:
86+
line = raw.strip()
87+
if not line or line.startswith("#"):
88+
continue
89+
for script in non_exec:
90+
if script not in line:
91+
continue
92+
# Position of the reference; everything before it must be prefix-y.
93+
for match in re.finditer(re.escape(script), line):
94+
head = line[:match.start()]
95+
head_wo_leaders = LEADERS.sub("", head).lstrip("./")
96+
if head_wo_leaders.strip():
97+
continue # something real precedes it → an argument
98+
if INTERPRETED.match(head.strip() + " "):
99+
continue # bash/sh/source foo.sh → mode irrelevant
100+
if head.strip() in {"", "-", "@"} or LEADERS.fullmatch(head):
101+
rel = path.relative_to(root)
102+
failures.append(
103+
f"{rel}:{number}: executes {script} directly, but its "
104+
f"committed mode is 100644\n"
105+
f" fix EITHER side: "
106+
f"'git update-index --chmod=+x {script}' or 'bash {script}'")
107+
break
108+
109+
if failures:
110+
for f in sorted(set(failures)):
111+
print("FAIL: " + f, file=sys.stderr)
112+
print(f"script exec-bit contract FAILED with {len(set(failures))} violation(s)",
113+
file=sys.stderr)
114+
sys.exit(1)
115+
print("PASS: no non-executable script is invoked as a command")
116+
PY

0 commit comments

Comments
 (0)