Skip to content

Commit 11eae42

Browse files
authored
ci: pin that the repository's own workflow files pass its admission rules (#624)
The compare endpoint returns every changed file (up to 300) on each request and paginates only the commits, so the admission loop that asked for page 2 got `files: null` and refused any pull request with 100 or more files before a pod was requested. Both the admit job and the hosted result job now make one request to the base...head compare and fail closed when `files` is missing or holds 300 rows, which is GitHub's cap. Row, filename and rename checks are unchanged. The preflight pin requires the new reader and refuses the paging loop, and the tests run the real step text against a fake gh. docs/ci.md replaces the sentence beginning "Admission checks the live PR, then reads the payload-bound compare list with" with one that states the single read and the 300-file refusal. The page keeps its line count. Admission refused main's own release.yml (the matrix runner under its fetched path) for every pull request, and no preflight stage ran the admission rules over the real workflow set. A new row copies the real .github workflows, actions and actionlint config into a temporary directory and expects no findings, and a mutation row restores the pre-fix literal-runner comparison in a copy of the checker source and expects exactly the release.yml finding. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent a991b4e commit 11eae42

4 files changed

Lines changed: 425 additions & 77 deletions

File tree

‎.github/workflows/gke-pr.yml‎

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -121,37 +121,32 @@ jobs:
121121
repo = os.environ["REPO"]
122122
base = os.environ["BASE_SHA"]
123123
head = os.environ["HEAD_SHA"]
124-
page = 1
125124
paths = []
126-
while True:
127-
endpoint = f"repos/{repo}/compare/{base}...{head}?per_page=100&page={page}"
128-
result = subprocess.run(["gh", "api", endpoint], check=True,
129-
capture_output=True, text=True)
130-
response = json.loads(result.stdout)
131-
rows = response.get("files")
132-
if not isinstance(rows, list):
133-
raise SystemExit("compare response has no readable files list")
134-
for row in rows:
135-
if not isinstance(row, dict):
136-
raise SystemExit("compare response has an unreadable file row")
137-
filename = row.get("filename")
138-
if (not isinstance(filename, str) or "\x00" in filename
139-
or any(part in ("", ".", "..") for part in filename.split("/"))):
140-
raise SystemExit("compare response has an unreadable filename")
141-
paths.append(filename)
142-
if row.get("status") == "renamed" and "previous_filename" not in row:
143-
raise SystemExit("compare response is missing a rename origin")
144-
if "previous_filename" in row:
145-
previous = row["previous_filename"]
146-
if (not isinstance(previous, str) or "\x00" in previous
147-
or any(part in ("", ".", "..") for part in previous.split("/"))):
148-
raise SystemExit("compare response has an unreadable previous filename")
149-
paths.append(previous)
150-
if len(paths) >= 3000:
151-
raise SystemExit("compare response is truncated at 3000 files")
152-
if len(rows) < 100:
153-
break
154-
page += 1
125+
endpoint = f"repos/{repo}/compare/{base}...{head}"
126+
result = subprocess.run(["gh", "api", endpoint], check=True,
127+
capture_output=True, text=True)
128+
response = json.loads(result.stdout)
129+
rows = response.get("files")
130+
if not isinstance(rows, list):
131+
raise SystemExit("compare response has no readable files list")
132+
if len(rows) >= 300:
133+
raise SystemExit("PR changes 300+ files: admission by compare is truncated")
134+
for row in rows:
135+
if not isinstance(row, dict):
136+
raise SystemExit("compare response has an unreadable file row")
137+
filename = row.get("filename")
138+
if (not isinstance(filename, str) or "\x00" in filename
139+
or any(part in ("", ".", "..") for part in filename.split("/"))):
140+
raise SystemExit("compare response has an unreadable filename")
141+
paths.append(filename)
142+
if row.get("status") == "renamed" and "previous_filename" not in row:
143+
raise SystemExit("compare response is missing a rename origin")
144+
if "previous_filename" in row:
145+
previous = row["previous_filename"]
146+
if (not isinstance(previous, str) or "\x00" in previous
147+
or any(part in ("", ".", "..") for part in previous.split("/"))):
148+
raise SystemExit("compare response has an unreadable previous filename")
149+
paths.append(previous)
155150
if not paths:
156151
raise SystemExit("compare response has no changed paths")
157152
Path(os.environ["PATH_FILE"]).write_bytes(
@@ -444,39 +439,33 @@ jobs:
444439
from pathlib import Path
445440
import subprocess
446441
447-
page = 1
448442
paths = []
449-
while True:
450-
endpoint = (f"repos/{os.environ['REPO']}/compare/"
451-
f"{os.environ['BASE_SHA']}...{os.environ['HEAD_SHA']}"
452-
f"?per_page=100&page={page}")
453-
response = json.loads(subprocess.run(
454-
["gh", "api", endpoint], check=True,
455-
capture_output=True, text=True).stdout)
456-
rows = response.get("files")
457-
if not isinstance(rows, list):
458-
raise SystemExit("second compare response is unreadable")
459-
for row in rows:
460-
if not isinstance(row, dict):
461-
raise SystemExit("second compare response has an unreadable file row")
462-
filename = row.get("filename")
463-
if (not isinstance(filename, str) or "\x00" in filename
464-
or any(part in ("", ".", "..") for part in filename.split("/"))):
465-
raise SystemExit("second compare filename is unreadable")
466-
paths.append(filename)
467-
if row.get("status") == "renamed" and "previous_filename" not in row:
468-
raise SystemExit("second compare response is missing a rename origin")
469-
if "previous_filename" in row:
470-
previous = row["previous_filename"]
471-
if (not isinstance(previous, str) or "\x00" in previous
472-
or any(part in ("", ".", "..") for part in previous.split("/"))):
473-
raise SystemExit("second previous filename is unreadable")
474-
paths.append(previous)
475-
if len(paths) >= 3000:
476-
raise SystemExit("second compare response is truncated")
477-
if len(rows) < 100:
478-
break
479-
page += 1
443+
endpoint = (f"repos/{os.environ['REPO']}/compare/"
444+
f"{os.environ['BASE_SHA']}...{os.environ['HEAD_SHA']}")
445+
response = json.loads(subprocess.run(
446+
["gh", "api", endpoint], check=True,
447+
capture_output=True, text=True).stdout)
448+
rows = response.get("files")
449+
if not isinstance(rows, list):
450+
raise SystemExit("second compare response is unreadable")
451+
if len(rows) >= 300:
452+
raise SystemExit("second compare response is truncated at 300 files")
453+
for row in rows:
454+
if not isinstance(row, dict):
455+
raise SystemExit("second compare response has an unreadable file row")
456+
filename = row.get("filename")
457+
if (not isinstance(filename, str) or "\x00" in filename
458+
or any(part in ("", ".", "..") for part in filename.split("/"))):
459+
raise SystemExit("second compare filename is unreadable")
460+
paths.append(filename)
461+
if row.get("status") == "renamed" and "previous_filename" not in row:
462+
raise SystemExit("second compare response is missing a rename origin")
463+
if "previous_filename" in row:
464+
previous = row["previous_filename"]
465+
if (not isinstance(previous, str) or "\x00" in previous
466+
or any(part in ("", ".", "..") for part in previous.split("/"))):
467+
raise SystemExit("second previous filename is unreadable")
468+
paths.append(previous)
480469
if not paths:
481470
raise SystemExit("second compare response has no changed paths")
482471
Path(os.environ["PATH_FILE"]).write_bytes(

‎docs/ci.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,8 +1518,8 @@ variants already include a visible link to <https://pineforge.dev> on every
15181518
page rendered by the theme, including source listings.
15191519

15201520
The only job of `ci.yml` is `authz`; PR proof work lives in `gke-pr`.
1521-
Admission checks the live PR, then reads the payload-bound compare list with
1522-
the base tree's [`scripts/ci_docs_only.py`](../scripts/ci_docs_only.py).
1521+
Admission checks the live PR, reads the payload-bound compare list once and fails closed at 300 files;
1522+
the base tree's [`scripts/ci_docs_only.py`](../scripts/ci_docs_only.py) classifies the paths.
15231523
A changed path is documentation when it is a Markdown file (`*.md`) or lies
15241524
under `docs/`, unless it lies under `.github/`, `benchmarks/`, `scripts/` or
15251525
`tests/`, is a CMake file or a git control file such as `.gitattributes`, or is

‎scripts/ci_preflight.py‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,17 +1710,33 @@ def gke_admit_workflow_findings(workflow: str, name: str = 'gke-pr.yml') -> list
17101710
'BASE_SHA': '${{ ' + identity_output + '.outputs.base_sha }}',
17111711
'HEAD_SHA': '${{ ' + identity_output + '.outputs.head_sha }}',
17121712
}
1713+
if job == 'admit':
1714+
endpoint_lines = {'endpoint = f"repos/{repo}/compare/{base}...{head}"'}
1715+
unreadable = 'compare response has no readable files list'
1716+
truncated = 'PR changes 300+ files: admission by compare is truncated'
1717+
else:
1718+
endpoint_lines = {
1719+
'endpoint = (f"repos/{os.environ[\'REPO\']}/compare/"',
1720+
'f"{os.environ[\'BASE_SHA\']}...{os.environ[\'HEAD_SHA\']}")',
1721+
}
1722+
unreadable = 'second compare response is unreadable'
1723+
truncated = 'second compare response is truncated at 300 files'
17131724
required_lines = {
1725+
'rows = response.get("files")',
17141726
'if not isinstance(rows, list):',
1727+
f'raise SystemExit("{unreadable}")',
1728+
'if len(rows) >= 300:',
1729+
f'raise SystemExit("{truncated}")',
17151730
'if not isinstance(row, dict):',
17161731
'if row.get("status") == "renamed" and "previous_filename" not in row:',
17171732
'if "previous_filename" in row:',
1718-
'if len(paths) >= 3000:',
1719-
'if len(rows) < 100:',
1720-
'page += 1',
17211733
'if not paths:',
1722-
}
1734+
} | endpoint_lines
17231735
if (not reader or not required_lines <= reader_lines
1736+
or any(token in reader for token in (
1737+
'while True:', 'page = ', 'page +=', 'per_page=', '--paginate',
1738+
'if len(paths) >= 3000:'))
1739+
or reader.count('["gh", "api", endpoint]') != 1
17241740
or _step_values(reader, 'shell') != ['python3 {0}']
17251741
or any(_job_values(reader_env, key) != [value] for key, value in bindings.items())
17261742
or 'check=True' not in reader or '...{' not in reader):

0 commit comments

Comments
 (0)