open-standards/scripts/pr-touches-paths.py
Transaction Science 26a6c1454d
Some checks failed
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 1m27s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 7m4s
lockfiles / every Cargo.lock is current (pull_request) Successful in 42s
spec citations resolve / Code cites no section its SPEC lacks (pull_request) Successful in 7s
standards workspaces build + test / arl-rs (pull_request) Successful in 1m17s
standards workspaces build + test / eoc-rs (pull_request) Successful in 2m9s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 1m14s
standards workspaces build + test / jcp-rs (pull_request) Successful in 1m40s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 1m15s
standards workspaces build + test / proof-rs (pull_request) Successful in 1m32s
standards workspaces build + test / sense-rs (pull_request) Successful in 1m8s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m26s
tests in CI / every test file is run by a job or listed with its reason (pull_request) Successful in 4s
workflow hygiene / every workflow supersedes its own queue (pull_request) Successful in 4s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 3m55s
smart-byte conformance gate / does this change touch it (pull_request) Successful in 30s
standards workspaces build + test / jouleclaw-rs (pull_request) Successful in 10m42s
standards workspaces build + test / aac-rs (pull_request) Successful in 15m49s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 5m0s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 1m19s
standards workspaces build + test / map-rs (pull_request) Successful in 1m22s
standards workspaces build + test / mesh-rs (pull_request) Successful in 1m37s
wai cross-architecture byte-equality / does this change touch it (pull_request) Successful in 6s
WAI conformance / does this change touch it (pull_request) Successful in 6s
WAI energy receipts / does this change touch it (pull_request) Successful in 5s
wai formal verification (integer core) / does this change touch it (pull_request) Successful in 6s
WAI JPEG-AI whole decode (pinned inputs, required) / does this change touch it (pull_request) Successful in 6s
WAI neural decoders end-to-end / does this change touch it (pull_request) Successful in 6s
WAI neural sink gates / does this change touch it (pull_request) Successful in 8s
wai-ops integer operators / does this change touch it (pull_request) Successful in 8s
wai-quantum WebGPU member / does this change touch it (pull_request) Successful in 8s
WAI mbt2018_mean integer decode (regenerated vectors) / does this change touch it (pull_request) Successful in 8s
wai-vector vector graphics / does this change touch it (pull_request) Successful in 10s
wai-web wasm32 / does this change touch it (pull_request) Successful in 11s
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Has been cancelled
wai-vector vector graphics / linux-aarch64 (pull_request) Has been cancelled
wai-vector vector graphics / linux-x86_64 (pull_request) Has been cancelled
wai-vector vector graphics / macos-arm64 (pull_request) Has been cancelled
wai-vector vector graphics / wasm32-wasip2 (wasmtime) (pull_request) Has been cancelled
wai-vector vector graphics / wasm32 under Node (pull_request) Has been cancelled
wai-vector vector graphics / wasm32 in three browser engines (pull_request) Has been cancelled
wai-vector vector graphics / fuzz, peak allocation, comparison count (pull_request) Has been cancelled
wai-vector vector graphics / independent checker (Python) (pull_request) Has been cancelled
WAI mbt2018_mean integer decode (regenerated vectors) / regenerate mbt2018_mean integer vectors → Rust decode, required (pull_request) Has been cancelled
wai-quantum WebGPU member / shader checks · browser build · wasip2 inertness · MSRV (pull_request) Has been cancelled
wai-quantum WebGPU member / member · software Vulkan (linux) (pull_request) Has been cancelled
wai-quantum WebGPU member / member · Metal (macos) (pull_request) Has been cancelled
wai-quantum WebGPU member / member · browser WebGPU (macos) (pull_request) Has been cancelled
wai-ops integer operators / linux-aarch64 (pull_request) Has been cancelled
wai-ops integer operators / linux-x86_64 (pull_request) Has been cancelled
wai-ops integer operators / macos-arm64 (pull_request) Has been cancelled
wai-ops integer operators / wasm32-wasip2 (wasmtime) (pull_request) Has been cancelled
wai-ops integer operators / wasm32 under Node (pull_request) Has been cancelled
wai-ops integer operators / independent checker (Python) (pull_request) Has been cancelled
WAI neural sink gates / model-free refusals of the neural sink (pull_request) Has been cancelled
WAI neural decoders end-to-end / synthetic fixtures → Rust decode → reference (±4) (pull_request) Has been cancelled
wai-quantum WebGPU member / member · discrete GPU, Vulkan (jetson-hub) (pull_request) Has been cancelled
WAI JPEG-AI whole decode (pinned inputs, required) / fetch pinned JPEG-AI inputs → whole decode + pixel hash, required (pull_request) Has been cancelled
wai formal verification (integer core) / every harness in one shard (pull_request) Has been cancelled
wai formal verification (integer core) / kani (arith) (pull_request) Has been cancelled
wai formal verification (integer core) / kani (isqrt512) (pull_request) Has been cancelled
wai formal verification (integer core) / kani (plan) (pull_request) Has been cancelled
wai formal verification (integer core) / kani (sound) (pull_request) Has been cancelled
wai formal verification (integer core) / kani (stage) (pull_request) Has been cancelled
wai formal verification (integer core) / kani (rans64-t2) (pull_request) Has been cancelled
wai formal verification (integer core) / kani (stage-long) (pull_request) Has been cancelled
wai formal verification (integer core) / kani (integer-core) (pull_request) Has been cancelled
WAI energy receipts / energy receipts · linux (pull_request) Has been cancelled
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Has been cancelled
WAI energy receipts / energy receipts · macos (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · linux (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Has been cancelled
WAI conformance / cargo-class corpora · macos (pull_request) Has been cancelled
WAI conformance / quantum core and corpus under wasm32-wasip2 (wasmtime) (pull_request) Has been cancelled
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Has been cancelled
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Has been cancelled
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · linux (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Has been cancelled
WAI conformance / cross-arch byte-equality · macos (pull_request) Has been cancelled
WAI conformance / codec wrappers · fuzz smoke, text decode limits, C entry points, provenance, the semantic path (pull_request) Has been cancelled
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Has been cancelled
wai cross-architecture byte-equality / linux-aarch64 (pull_request) Has been cancelled
wai cross-architecture byte-equality / linux-x86_64 (pull_request) Has been cancelled
wai cross-architecture byte-equality / macos-arm64 (reference) (pull_request) Has been cancelled
smart-byte conformance gate / Validate conformance JSON files (pull_request) Has been cancelled
smart-byte conformance gate / Second implementation reproduces every vector (pull_request) Has been cancelled
smart-byte conformance gate / Spec changes require vector-pack updates (pull_request) Has been cancelled
smart-byte conformance gate / VERSIONS.md and README.md must exist (pull_request) Has been cancelled
standards workspaces build + test / openpay (pull_request) Has been cancelled
pr-touches-paths: a comment inside a path list no longer ends it
The parser stopped reading a paths: list at its first comment line, so every
glob after it was dropped and a pull request touching only those paths was
answered false: its workflow's tests skipped, silently. wai-http, which has
used this gate for weeks, was read as 10 of its 41 paths. The list now
continues past comments and blank lines, and a trailing comment is not part of
a glob; every workflow's list is read exactly as its YAML states it. The
self-test gains the case, and fails it with the old parser.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-14 04:21:43 -04:00

110 lines
4 KiB
Python
Executable file

#!/usr/bin/env python3
"""Does this pull request's own diff touch any path its workflow filters on?
Forgejo matches a workflow's `paths:` filter against the **push delta**, not the
pull request's diff. A rebase moves a branch across every commit main has
gained, so its push delta touches nearly every path and every path-filtered
workflow fires. Measured on this repo: a jcp-only change pushed to a fresh
branch ran 2 workflows; the same change force-pushed after a rebase ran 15,
including JPEG-AI whole decode and wai-pack on three platforms. That is what
fills the queue, and it delays everyone's real jobs behind irrelevant ones.
This reads the path list out of the workflow file itself — one source of truth,
rather than a third copy of the list to drift from the two `on:` blocks — and
compares it against `git diff --name-only BASE...HEAD`.
pr-touches-paths.py <workflow.yml> <base-sha> <head-sha>
Prints `true` or `false`. **Fails open**: anything it cannot determine prints
`true`, because a wrong `false` silently skips a test and a wrong `true` only
costs runner time. A gate that guesses must guess toward running.
"""
import re
import subprocess
import sys
from pathlib import Path
def paths_of(workflow: Path) -> list[str]:
"""The union of every `paths:` list under `on:` in this workflow.
Parsed rather than imported from a library: the runner image has no PyYAML
guaranteed, and the shape here is a flat `paths:` followed by `- 'glob'`
lines. A list this parser fails to read yields none, which fails open.
"""
globs: list[str] = []
in_paths = False
for line in workflow.read_text().splitlines():
if re.match(r"\s*paths(-ignore)?:\s*$", line):
in_paths = True
continue
if in_paths:
stripped = line.strip()
# A comment or a blank line inside the list does not end it. (It used to:
# every glob after a list's first comment was dropped, and a pull request
# touching only those paths was answered `false`.)
if not stripped or stripped.startswith("#"):
continue
m = re.match(r"\s*-\s*'([^']+)'\s*(#.*)?$", line) or re.match(r'\s*-\s*"([^"]+)"\s*(#.*)?$', line)
if m:
globs.append(m.group(1))
continue
if stripped.startswith("- "):
globs.append(re.sub(r"\s+#.*$", "", stripped[2:]).strip())
continue
in_paths = False
return globs
def matches(path: str, glob: str) -> bool:
"""`glob` in the Actions sense: `**` spans separators, `*` does not."""
rx = []
i = 0
while i < len(glob):
if glob.startswith("**", i):
rx.append(".*")
i += 2
elif glob[i] == "*":
rx.append("[^/]*")
i += 1
elif glob[i] == "?":
rx.append("[^/]")
i += 1
else:
rx.append(re.escape(glob[i]))
i += 1
return re.fullmatch("".join(rx), path) is not None
def main() -> None:
if len(sys.argv) != 4:
print("true") # cannot tell: run it
return
workflow, base, head = Path(sys.argv[1]), sys.argv[2], sys.argv[3]
if not workflow.is_file() or not base or not head:
print("true")
return
globs = paths_of(workflow)
if not globs:
# No filter, or a shape this parser does not read: the workflow wanted
# to run on everything, or we cannot say it did not.
print("true")
return
try:
out = subprocess.run(
["git", "diff", "--name-only", f"{base}...{head}"],
capture_output=True, text=True, check=True,
).stdout
except (subprocess.CalledProcessError, OSError):
print("true")
return
changed = [l for l in out.splitlines() if l.strip()]
if not changed:
print("true")
return
hit = any(matches(p, g) for p in changed for g in globs)
print("true" if hit else "false")
if __name__ == "__main__":
main()