From ce1de59601b3a948070e458d9427a763f1eefc9b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 23:31:35 +0000 Subject: [PATCH 1/2] CI: run only the jobs a commit needs A changes job (.github/scripts/ci-changes.sh, plain git diff) gates every job in rust.yml: documentation alone runs none of them; the TeX Live fixture rebuild (about 6 minutes, mostly apt) runs when fixtures or xtask change and weekly; deterministic fuzzing when the parser crates change, now with a build cache. Rust caches are saved only from main so PRs start warm; newer commits cancel older runs on main too. A weekly full run catches TeX Live drift and new cargo-deny advisories. Tested by .github/tests/test_ci_changes.py; documented in docs/releasing.md. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Xj9ekYmyESdZUsW8uWkzgv --- .github/scripts/ci-changes.sh | 40 ++++++++++++++++++ .github/tests/test_ci_changes.py | 65 ++++++++++++++++++++++++++++ .github/workflows/rust.yml | 72 +++++++++++++++++++++++++++++++- CHANGELOG.md | 7 ++++ docs/releasing.md | 21 ++++++++++ 5 files changed, 204 insertions(+), 1 deletion(-) create mode 100755 .github/scripts/ci-changes.sh create mode 100644 .github/tests/test_ci_changes.py diff --git a/.github/scripts/ci-changes.sh b/.github/scripts/ci-changes.sh new file mode 100755 index 0000000..c9ef003 --- /dev/null +++ b/.github/scripts/ci-changes.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# Which CI jobs a commit needs. Prints `name=true|false` lines for $GITHUB_OUTPUT. +# +# Usage: ci-changes.sh +# An empty or all-zero base (first push, workflow_dispatch, schedule) or a diff that +# cannot be computed selects everything: when unsure, run the job. +set -euo pipefail + +base="${1:-}" +head="${2:-HEAD}" + +all() { + for k in rust deps fixtures fuzz perf vscode; do echo "$k=true"; done +} + +if [[ -z "$base" || "$base" =~ ^0+$ ]] || ! files=$(git diff --name-only "$base" "$head" 2>/dev/null); then + all + exit 0 +fi + +# This script and the workflow change what runs, so they select everything. +if grep -qE '^(\.github/workflows/rust\.yml|\.github/scripts/ci-changes\.sh)$' <<<"$files"; then + all + exit 0 +fi + +match() { grep -qE "$1" <<<"$files" && echo true || echo false; } + +# Rust code, its tests and anything the lint job checks. +echo "rust=$(match '^(crates/|xtask/|fuzz/|fixtures/|Cargo\.(toml|lock)$|deny\.toml$|clippy\.toml$|\.cargo/|site/schema/|packaging/action/|\.github/tests/|\.github/dependabot\.yml$)')" +# Dependency licences and advisories (cargo-deny). +echo "deps=$(match '^(Cargo\.(toml|lock)$|deny\.toml$|(crates/[^/]+|xtask)/Cargo\.toml$)')" +# Fixture PDFs rebuilt with the runner's TeX Live (also weekly, for TeX Live drift). +echo "fixtures=$(match '^(fixtures/|xtask/)')" +# Deterministic fuzzing of the parsers (random fuzzing runs nightly in fuzz.yml). +echo "fuzz=$(match '^(fuzz/|crates/proofback-(synctex|tex|pdf|model)/|Cargo\.lock$)')" +# Performance budgets. +echo "perf=$(match '^(crates/|xtask/|fixtures/generate\.py$|Cargo\.(toml|lock)$)')" +# VS Code extension. +echo "vscode=$(match '^integrations/vscode/')" diff --git a/.github/tests/test_ci_changes.py b/.github/tests/test_ci_changes.py new file mode 100644 index 0000000..100bc13 --- /dev/null +++ b/.github/tests/test_ci_changes.py @@ -0,0 +1,65 @@ +"""`.github/scripts/ci-changes.sh` picks the CI jobs a commit needs. + +Each case builds a throwaway git repository with one commit that changes the +given paths, and checks which jobs the script turns on. +""" +import pathlib +import subprocess +import tempfile +import unittest + +SCRIPT = pathlib.Path(__file__).resolve().parents[1] / "scripts" / "ci-changes.sh" +JOBS = ("rust", "deps", "fixtures", "fuzz", "perf", "vscode") + + +def run(args, cwd): + return subprocess.run(args, cwd=cwd, check=True, capture_output=True, text=True).stdout + + +def selected(paths): + with tempfile.TemporaryDirectory() as d: + run(["git", "init", "-q"], d) + run(["git", "-c", "user.email=ci@example.invalid", "-c", "user.name=ci", "commit", "-q", "--allow-empty", "-m", "base"], d) + base = run(["git", "rev-parse", "HEAD"], d).strip() + for p in paths: + f = pathlib.Path(d, p) + f.parent.mkdir(parents=True, exist_ok=True) + f.write_text("x\n") + run(["git", "add", "-A"], d) + run(["git", "-c", "user.email=ci@example.invalid", "-c", "user.name=ci", "commit", "-q", "-m", "change"], d) + out = run(["bash", str(SCRIPT), base, "HEAD"], d) + flags = dict(line.split("=", 1) for line in out.split()) + return {k for k in JOBS if flags[k] == "true"} + + +class CiChanges(unittest.TestCase): + def test_documentation_alone_runs_nothing(self): + self.assertEqual(selected(["README.md", "docs/PLAN.md", "CHANGELOG.md"]), set()) + + def test_rust_code(self): + self.assertEqual(selected(["crates/proofback-anchor/src/lib.rs"]), {"rust", "perf"}) + + def test_parser_crates_also_fuzz(self): + self.assertEqual(selected(["crates/proofback-synctex/src/lib.rs"]), {"rust", "fuzz", "perf"}) + + def test_dependencies(self): + self.assertEqual(selected(["Cargo.lock"]), {"rust", "deps", "fuzz", "perf"}) + + def test_fixtures(self): + self.assertEqual(selected(["fixtures/thesis-basic/main.tex"]), {"rust", "fixtures"}) + + def test_vscode_alone(self): + self.assertEqual(selected(["integrations/vscode/package.json"]), {"vscode"}) + + def test_workflow_or_script_runs_everything(self): + self.assertEqual(selected([".github/workflows/rust.yml"]), set(JOBS)) + self.assertEqual(selected([".github/scripts/ci-changes.sh"]), set(JOBS)) + + def test_unknown_base_runs_everything(self): + for base in ("", "0" * 40): + out = run(["bash", str(SCRIPT), base, "HEAD"], SCRIPT.parent) + self.assertTrue(all(line.endswith("=true") for line in out.split()), out) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b80046e..dc5dd19 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -4,21 +4,59 @@ on: pull_request: push: branches: [main] + # Weekly full run: rebuilds the fixtures with the runner's current TeX Live, so + # drift shows up even in weeks without fixture changes. + schedule: + - cron: "23 4 * * 1" workflow_dispatch: permissions: contents: read +# A newer commit on the same branch (main included) supersedes the older run. concurrency: group: rust-${{ github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} + cancel-in-progress: true env: CARGO_TERM_COLOR: always RUSTFLAGS: -D warnings jobs: + # Decides which jobs this commit needs (.github/scripts/ci-changes.sh): a change to + # documentation alone runs none of the jobs below. Schedule and manual runs, and + # any change to this workflow or the script, run everything. + changes: + runs-on: ubuntu-latest + timeout-minutes: 5 + outputs: + rust: ${{ steps.c.outputs.rust }} + deps: ${{ steps.c.outputs.deps }} + fixtures: ${{ steps.c.outputs.fixtures }} + fuzz: ${{ steps.c.outputs.fuzz }} + perf: ${{ steps.c.outputs.perf }} + vscode: ${{ steps.c.outputs.vscode }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + fetch-depth: 0 + - id: c + env: + EVENT: ${{ github.event_name }} + BEFORE: ${{ github.event.before }} + run: | + case "$EVENT" in + # The checked-out merge commit's first parent is the current base. + pull_request) base=$(git rev-parse HEAD^1) ;; + push) base="$BEFORE" ;; + *) base="" ;; + esac + .github/scripts/ci-changes.sh "$base" HEAD | tee -a "$GITHUB_OUTPUT" + lint: + needs: changes + if: needs.changes.outputs.rust == 'true' runs-on: ubuntu-latest timeout-minutes: 20 steps: @@ -30,6 +68,8 @@ jobs: toolchain: stable components: rustfmt, clippy - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} - run: cargo fmt --all --check - run: cargo clippy --workspace --all-targets --locked - run: cargo xtask schema --check @@ -41,6 +81,8 @@ jobs: python3 -m unittest discover -s .github/tests -v test: + needs: changes + if: needs.changes.outputs.rust == 'true' strategy: fail-fast: false matrix: @@ -55,12 +97,16 @@ jobs: with: toolchain: stable - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} - run: cargo xtask pdfium - run: cargo test --workspace --locked env: PROOFBACK_REQUIRE_PDFIUM: "1" msrv: + needs: changes + if: needs.changes.outputs.rust == 'true' runs-on: ubuntu-latest timeout-minutes: 20 steps: @@ -71,9 +117,13 @@ jobs: with: toolchain: "1.92" - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} - run: cargo check --workspace --locked wasm: + needs: changes + if: needs.changes.outputs.rust == 'true' runs-on: ubuntu-latest timeout-minutes: 20 steps: @@ -86,9 +136,13 @@ jobs: targets: wasm32-unknown-unknown components: clippy - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} - run: cargo clippy --locked --target wasm32-unknown-unknown -p proofback-model -p proofback-synctex -p proofback-tex -p proofback-wasm deny: + needs: changes + if: needs.changes.outputs.deps == 'true' runs-on: ubuntu-latest timeout-minutes: 10 steps: @@ -98,6 +152,8 @@ jobs: - uses: EmbarkStudios/cargo-deny-action@81891abc19297b21343b15ef67dc61e4aea74fda # v2.1.4 fixtures: + needs: changes + if: needs.changes.outputs.fixtures == 'true' runs-on: ubuntu-latest timeout-minutes: 20 steps: @@ -108,6 +164,8 @@ jobs: with: toolchain: stable - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} - name: Install TeX Live run: sudo apt-get update && sudo apt-get install -y --no-install-recommends texlive-latex-base texlive-latex-recommended texlive-fonts-recommended pandoc - name: Rebuild fixtures with this runner's TeX Live and rerun tests @@ -119,6 +177,8 @@ jobs: cargo test --workspace --locked perf: + needs: changes + if: needs.changes.outputs.perf == 'true' runs-on: ubuntu-latest timeout-minutes: 30 steps: @@ -129,6 +189,8 @@ jobs: with: toolchain: stable - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + save-if: ${{ github.ref == 'refs/heads/main' }} - name: Install TeX Live run: sudo apt-get update && sudo apt-get install -y --no-install-recommends texlive-latex-base texlive-latex-recommended texlive-fonts-recommended - name: Build the 300-page performance fixture @@ -145,6 +207,8 @@ jobs: run: cargo test --release --locked -p proofback-corpus --test perf -- --nocapture vscode: + needs: changes + if: needs.changes.outputs.vscode == 'true' runs-on: ubuntu-latest timeout-minutes: 10 defaults: @@ -164,6 +228,8 @@ jobs: - run: npm run package fuzz: + needs: changes + if: needs.changes.outputs.fuzz == 'true' runs-on: ubuntu-latest timeout-minutes: 20 steps: @@ -177,6 +243,10 @@ jobs: - uses: taiki-e/install-action@fe3acb53a98b62c772db35de75ce0e4595e7ca8c # v2.90.8 with: tool: cargo-fuzz@0.13.2 + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + workspaces: fuzz -> target + save-if: ${{ github.ref == 'refs/heads/main' }} # Fixed seed and run count: the result depends only on the code, so a pull # request turns red only for a bug it can reproduce. Random, longer fuzzing # runs nightly in fuzz.yml. diff --git a/CHANGELOG.md b/CHANGELOG.md index 5537ecf..87238ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ the JSON schema is versioned separately (`schema_version` in round files). ## Unreleased +### Continuous integration + +- CI runs only the jobs a commit needs: a documentation-only commit runs none of the + build and test jobs, the TeX Live fixture rebuild runs when fixtures change (and + weekly), deterministic fuzzing when the parsers change. Build caches are shared + from `main`, the fuzz build is cached, and a newer commit cancels an older run. + ### Interop with overfull 4.0 - `docs/interop.md` records overfull 4.0's exit code `70` for internal errors diff --git a/docs/releasing.md b/docs/releasing.md index 4f5821f..4a9ad22 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -68,6 +68,27 @@ of release files with: python3 packaging/check-release-files.py ``` +## Continuous integration + +`.github/workflows/rust.yml` runs only the jobs a commit needs. Its first job, +`changes`, runs `.github/scripts/ci-changes.sh` on the commit's changed files: + +| Job | Runs when these change | +|---|---| +| lint, test (Linux, macOS, Windows), msrv, wasm | Rust code, fixtures, `xtask`, Cargo files, `site/schema`, the Action script, `.github/tests`, Dependabot config | +| deny | Cargo manifests, `Cargo.lock`, `deny.toml` | +| fuzz (deterministic) | `fuzz/`, the parser crates (`synctex`, `tex`, `pdf`, `model`), `Cargo.lock` | +| perf | Rust code, `xtask`, the fixture generator, Cargo files | +| fixtures (TeX Live rebuild) | `fixtures/`, `xtask/` | +| vscode | `integrations/vscode/` | + +A change to documentation alone runs none of them. A change to the workflow or the +script, a manual run, and the weekly run on Monday run everything; the weekly run +catches TeX Live drift in the fixtures and new advisories in `cargo deny`. Nightly +random fuzzing stays in `fuzz.yml`. Rust build caches are saved only from `main`, +so pull requests start from a warm cache, and a newer commit cancels the older run +on the same branch. `.github/tests/test_ci_changes.py` checks the selection. + ## Dependency updates Dependabot opens one pull request a week, on Monday, for every ecosystem together: From f37768daff7782683597892d8b90b127f053103b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 23:33:07 +0000 Subject: [PATCH 2/2] CI: macOS tests after merge, not on pull requests Every macOS failure in the last 40 runs was a job that waited 15 minutes for a runner and was cancelled (GitHub capacity for macOS arm64). Pull requests test on Linux and Windows; macOS runs on main, weekly and on manual runs. Release builds still use macOS. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Xj9ekYmyESdZUsW8uWkzgv --- .github/workflows/rust.yml | 5 ++++- CHANGELOG.md | 2 ++ docs/releasing.md | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dc5dd19..04dca18 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -86,7 +86,10 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + # macOS runners are often short (jobs wait 15 minutes and are cancelled), so + # pull requests test on Linux and Windows; macOS runs after merge on main, in + # the weekly run and on manual runs. Releases still build macOS binaries. + os: ${{ fromJSON(github.event_name == 'pull_request' && '["ubuntu-latest", "windows-latest"]' || '["ubuntu-latest", "macos-latest", "windows-latest"]') }} runs-on: ${{ matrix.os }} timeout-minutes: 30 steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 87238ec..4816819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ the JSON schema is versioned separately (`schema_version` in round files). build and test jobs, the TeX Live fixture rebuild runs when fixtures change (and weekly), deterministic fuzzing when the parsers change. Build caches are shared from `main`, the fuzz build is cached, and a newer commit cancels an older run. +- Pull requests test on Linux and Windows; macOS tests run after merge on `main` and + weekly, because macOS runners are often unavailable for 15 minutes at a time. ### Interop with overfull 4.0 diff --git a/docs/releasing.md b/docs/releasing.md index 4a9ad22..76df3df 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -75,14 +75,16 @@ python3 packaging/check-release-files.py | Job | Runs when these change | |---|---| -| lint, test (Linux, macOS, Windows), msrv, wasm | Rust code, fixtures, `xtask`, Cargo files, `site/schema`, the Action script, `.github/tests`, Dependabot config | +| lint, test (Linux and Windows; macOS too on `main`, weekly and manual runs), msrv, wasm | Rust code, fixtures, `xtask`, Cargo files, `site/schema`, the Action script, `.github/tests`, Dependabot config | | deny | Cargo manifests, `Cargo.lock`, `deny.toml` | | fuzz (deterministic) | `fuzz/`, the parser crates (`synctex`, `tex`, `pdf`, `model`), `Cargo.lock` | | perf | Rust code, `xtask`, the fixture generator, Cargo files | | fixtures (TeX Live rebuild) | `fixtures/`, `xtask/` | | vscode | `integrations/vscode/` | -A change to documentation alone runs none of them. A change to the workflow or the +macOS tests stay off pull requests because GitHub's macOS runners are often +unavailable (a job waits 15 minutes, then is cancelled); after a merge they run on +`main`. A change to documentation alone runs none of the jobs. A change to the workflow or the script, a manual run, and the weekly run on Monday run everything; the weekly run catches TeX Live drift in the fixtures and new advisories in `cargo deny`. Nightly random fuzzing stays in `fuzz.yml`. Rust build caches are saved only from `main`,