From f86f34bd903118b4c5f273fb7beec0b6497b8088 Mon Sep 17 00:00:00 2001 From: noah Date: Sun, 18 Oct 2026 20:23:07 -0600 Subject: [PATCH] Skip heavyweight Toolkit checks for documentation-only PRs --- .gitea/workflows/verify.yml | 32 ++++++++++++++++++ ci/pr-surface.py | 55 ++++++++++++++++++++++++++++++ ci/test-pr-surface.py | 67 +++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 ci/pr-surface.py create mode 100644 ci/test-pr-surface.py diff --git a/.gitea/workflows/verify.yml b/.gitea/workflows/verify.yml index 81104c0b..9ab99873 100644 --- a/.gitea/workflows/verify.yml +++ b/.gitea/workflows/verify.yml @@ -16,8 +16,31 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Detect changed surface + id: surface + run: python3 ci/pr-surface.py >> "$GITHUB_OUTPUT" + + - name: Check documentation change + if: steps.surface.outputs.surface == 'documentation' + run: | + base="$(git merge-base HEAD "origin/$GITHUB_BASE_REF")" + git diff --check "$base" HEAD + if git grep -nIE '^[[:space:]]*-----BEGIN (RSA |EC |OPENSSH )?PRIVATE KEY-----[[:space:]]*$' --; then + echo "private key material found in tracked source" >&2 + exit 1 + else + status=$? + [ "$status" -eq 1 ] + + - name: Check CI change surface + if: steps.surface.outputs.surface != 'documentation' + run: python3 ci/test-pr-surface.py - name: Install build dependencies + if: steps.surface.outputs.surface != 'documentation' run: | apt-get update -qq apt-get install -y -qq --no-install-recommends \ @@ -25,15 +48,18 @@ jobs: - name: Compute wxWidgets cache key id: wx-key + if: steps.surface.outputs.surface != 'documentation' run: bash ci/wx-cache-key.sh - name: Cache vendored wxWidgets build + if: steps.surface.outputs.surface != 'documentation' uses: actions/cache@v4 with: path: /root/.cache/wx-3.3.3-linux key: ${{ steps.wx-key.outputs.key }} - name: Build wxWidgets (once, then cached) + if: steps.surface.outputs.surface != 'documentation' run: | if [ ! -x "$WX_PREFIX/bin/wx-config" ]; then bash scripts/build-wx-linux.sh @@ -42,23 +68,28 @@ jobs: fi - name: Clippy (our crate, warnings are errors) + if: steps.surface.outputs.surface != 'documentation' run: | rustup component add clippy >/dev/null 2>&1 || true cargo clippy -p alkane-gui --no-deps --release --bins --offline -- -D warnings cargo clippy -p alkane-artifacts -p alkane-flash -p alkane-cli --all-targets --offline -- -D warnings - name: Build + if: steps.surface.outputs.surface != 'documentation' run: cargo build --release -p alkane-gui --offline - name: Unit tests + if: steps.surface.outputs.surface != 'documentation' run: | cargo test -p alkane-gui --offline cargo test -p alkane-artifacts -p alkane-flash -p alkane-cli --offline - name: Microbenchmarks + if: steps.surface.outputs.surface != 'documentation' run: cargo test -p alkane-gui -p alkane-artifacts --release --offline -- --ignored --nocapture bench_ --test-threads=1 - name: Headless UI self-test + if: steps.surface.outputs.surface != 'documentation' run: | apt-get update -qq && apt-get install -y -qq --no-install-recommends \ xvfb xauth dbus-x11 fonts-dejavu-core >/dev/null @@ -70,6 +101,7 @@ jobs: # runner must not fail the gate on it. Accepted advisories live in # .cargo/audit.toml. - name: Dependency audit (best-effort) + if: steps.surface.outputs.surface != 'documentation' continue-on-error: true run: | if command -v cargo-audit >/dev/null 2>&1; then diff --git a/ci/pr-surface.py b/ci/pr-surface.py new file mode 100644 index 00000000..f571cff5 --- /dev/null +++ b/ci/pr-surface.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +"""Classify a pull request for the documentation-only CI shortcut.""" + +import os +from pathlib import Path +import subprocess +import sys + + +ROOT = Path(__file__).resolve().parents[1] +DOC_FILES = {"README.md", "CONTRIBUTING.md", "CHANGELOG.md"} + + +def documentation_only(paths: list[str]) -> bool: + return bool(paths) and all( + path in DOC_FILES or + (path.startswith("docs/") and Path(path).suffix in {".md", ".txt"}) + for path in paths + ) + + +def changed_paths() -> list[str]: + if os.environ.get("GITHUB_EVENT_NAME") != "pull_request": + raise ValueError("not a pull request") + if os.environ.get("GITHUB_BASE_REF") != "main": + raise ValueError("unknown base branch") + merge_base = subprocess.check_output( + ["git", "-C", str(ROOT), "merge-base", "HEAD", + "refs/remotes/origin/main"], + stderr=subprocess.DEVNULL, text=True, + ).strip() + if len(merge_base) != 40: + raise ValueError("missing merge base") + raw = subprocess.check_output( + ["git", "-C", str(ROOT), "diff", "--name-only", "-z", + merge_base, "HEAD"], stderr=subprocess.DEVNULL, + ) + return [path.decode("utf-8", "surrogateescape") + for path in raw.split(b"\0") if path] + + +def main() -> None: + try: + paths = changed_paths() + docs = documentation_only(paths) + except (OSError, subprocess.CalledProcessError, ValueError): + paths = [] + docs = False + print(f"surface={'documentation' if docs else 'full'}") + print(f"Changed paths: {len(paths)}", file=sys.stderr) + + +if __name__ == "__main__": + main() diff --git a/ci/test-pr-surface.py b/ci/test-pr-surface.py new file mode 100644 index 00000000..6f3b2c41 --- /dev/null +++ b/ci/test-pr-surface.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +"""Check that unknown changes cannot take the documentation-only CI path.""" + +import os +from pathlib import Path +import subprocess +import tempfile + +import importlib.util + + +SCRIPT = Path(__file__).with_name("pr-surface.py") +spec = importlib.util.spec_from_file_location("pr_surface", SCRIPT) +assert spec and spec.loader +pr_surface = importlib.util.module_from_spec(spec) +spec.loader.exec_module(pr_surface) + + +def git(directory: Path, *args: str) -> str: + return subprocess.check_output( + ["git", "-C", str(directory), *args], text=True, + stderr=subprocess.DEVNULL, + ).strip() + + +def main() -> None: + assert pr_surface.documentation_only(["README.md", "docs/setup.md"]) + for paths in ([], ["docs/generated.json"], ["src/main.rs"], + ["README.md", "ci/pr-surface.py"]): + assert not pr_surface.documentation_only(paths), paths + + with tempfile.TemporaryDirectory(prefix="alkane-toolkit-pr-surface-") as directory: + repo = Path(directory) + git(repo, "init", "-q") + git(repo, "config", "user.name", "CI Test") + git(repo, "config", "user.email", "ci@example.invalid") + (repo / "README.md").write_text("initial\n") + git(repo, "add", "README.md") + git(repo, "commit", "-qm", "base") + base = git(repo, "rev-parse", "HEAD") + git(repo, "update-ref", "refs/remotes/origin/main", base) + (repo / "README.md").write_text("documentation change\n") + git(repo, "commit", "-qam", "docs") + saved_root = pr_surface.ROOT + saved_env = dict(os.environ) + try: + pr_surface.ROOT = repo + os.environ["GITHUB_EVENT_NAME"] = "pull_request" + os.environ["GITHUB_BASE_REF"] = "main" + assert pr_surface.changed_paths() == ["README.md"] + os.environ.pop("GITHUB_BASE_REF") + try: + pr_surface.changed_paths() + except ValueError: + pass + else: + raise AssertionError("missing base must fall back to full checks") + finally: + pr_surface.ROOT = saved_root + os.environ.clear() + os.environ.update(saved_env) + print("Toolkit PR change surface: documentation shortcut and fallback PASS") + + +if __name__ == "__main__": + main()