Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/scripts/ci-changes.sh
Original file line number Diff line number Diff line change
@@ -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 <base-sha> <head-sha>
# 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/')"
65 changes: 65 additions & 0 deletions .github/tests/test_ci_changes.py
Original file line number Diff line number Diff line change
@@ -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()
77 changes: 75 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -41,10 +81,15 @@ jobs:
python3 -m unittest discover -s .github/tests -v

test:
needs: changes
if: needs.changes.outputs.rust == 'true'
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:
Expand All @@ -55,12 +100,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:
Expand All @@ -71,9 +120,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:
Expand All @@ -86,9 +139,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:
Expand All @@ -98,6 +155,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:
Expand All @@ -108,6 +167,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
Expand All @@ -119,6 +180,8 @@ jobs:
cargo test --workspace --locked

perf:
needs: changes
if: needs.changes.outputs.perf == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
Expand All @@ -129,6 +192,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
Expand All @@ -145,6 +210,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:
Expand All @@ -164,6 +231,8 @@ jobs:
- run: npm run package

fuzz:
needs: changes
if: needs.changes.outputs.fuzz == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
Expand All @@ -177,6 +246,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.
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ 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.
- 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

- `docs/interop.md` records overfull 4.0's exit code `70` for internal errors
Expand Down
23 changes: 23 additions & 0 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@ of release files with:
python3 packaging/check-release-files.py <folder> <version>
```

## 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 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/` |

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`,
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:
Expand Down