From d971810daa71e32c935fc31fd155491af9e889d8 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 15 Nov 2026 23:32:31 +0100 Subject: [PATCH] ci: run the Windows GPU tests only when their inputs change (#15247) The Windows runners render the GPU tests on WARP, Direct3D 12's CPU rasterizer, where photocraft-gpu's tests took half of the integration leg's test time. Pull requests now skip them on Windows unless they change photocraft-gpu, a workspace crate it depends on (from cargo metadata), or a non-documentation file outside the workspace packages. main, manual runs and full-ci PRs still run them on Windows, and the Linux gate runs them on every pull request. --- .github/workflows/ci.yml | 24 ++++++-- scripts/ci-windows-gpu-tests.py | 89 ++++++++++++++++++++++++++++ scripts/test-ci-windows-gpu-tests.py | 80 +++++++++++++++++++++++++ 3 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 scripts/ci-windows-gpu-tests.py create mode 100644 scripts/test-ci-windows-gpu-tests.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3040375d3..1d8544a9ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,11 @@ jobs: # get both. Other PRs get Windows when they touch code whose behaviour differs by platform: the # app shell, UI, text and fonts, GPU, pen input, native saves, build scripts or the lockfile. # Format changes must exercise the Windows-only publication barriers (#8034). macOS is tested - # only by release.yml. + # only by release.yml. `windows_gpu`: whether those Windows legs run photocraft-gpu's tests, which + # render on WARP, the CPU Direct3D 12 rasterizer, and took half of the integration leg's test time. + # Pull requests run them only when they change the GPU crate, a workspace crate it builds on, or + # a file outside the workspace packages other than documentation (scripts/ci-windows-gpu-tests.py, + # #15247); the Linux gate runs them on every pull request, and main runs them on Windows too. platforms: if: github.event.action != 'labeled' || github.event.label.name == 'full-ci' timeout-minutes: 10 @@ -86,6 +90,7 @@ jobs: runs-on: ubuntu-latest outputs: windows: ${{ steps.pick.outputs.windows }} + windows_gpu: ${{ steps.pick.outputs.windows_gpu }} web: ${{ steps.pick.outputs.web }} steps: - name: Harden runner @@ -104,6 +109,7 @@ jobs: run: | if [ "$EVENT" != pull_request ] || [ "$FULL" = true ]; then echo "windows=true" >> "$GITHUB_OUTPUT" + echo "windows_gpu=true" >> "$GITHUB_OUTPUT" echo "web=true" >> "$GITHUB_OUTPUT" exit 0 fi @@ -121,6 +127,8 @@ jobs: else echo "windows=false" >> "$GITHUB_OUTPUT" fi + gpu=$(python3 scripts/ci-windows-gpu-tests.py "$BASE") + echo "windows_gpu=$gpu" >> "$GITHUB_OUTPUT" # The Linux gate. Its rust-cache entry is the one `test (without heif)` restores. gate: @@ -144,7 +152,7 @@ jobs: timeout-minutes: 100 # fmt, clippy, layers, panel-commands, scorecard, tests, panic_hunt, doctests and the wasm32 check, with # `--locked --features heif`, then the missing-translations report (xtask/src/main.rs). - command: python3 scripts/test-ci-gpu-lavapipe.py && cargo xtask ci && python3 scripts/ci-gpu-lavapipe.py + command: python3 scripts/test-ci-gpu-lavapipe.py && python3 scripts/test-ci-windows-gpu-tests.py && cargo xtask ci && python3 scripts/ci-gpu-lavapipe.py # Windows tests run as two legs in parallel: the unit tests and the integration tests. As one job # they took ~28 min on the Windows runner; the legs take ~13 and ~15. Splitting the integration @@ -232,16 +240,24 @@ jobs: # The unit leg runs `--lib --bins` and the integration leg `--test '*'` (every # integration-test target); the feature selection stays the same, so both legs share the - # dependency cache. + # dependency cache. photocraft-gpu's tests run when the `platforms` job says they can be + # affected (`windows_gpu`); excluding the package also skips building its test binaries. - name: Test env: PART: ${{ matrix.part }} + GPU: ${{ needs.platforms.outputs.windows_gpu }} run: | case "$PART" in unit) targets=(--lib --bins) ;; *) targets=(--test '*') ;; esac - cargo nextest run --profile ci --workspace --locked --features heif "${targets[@]}" + skip=() + # Only an explicit `false` skips them: a missing output runs everything. + if [ "$GPU" = false ]; then + skip=(--exclude photocraft-gpu) + echo "::notice::photocraft-gpu's tests are skipped on Windows: this pull request changes nothing they are built from (the Linux gate still runs them)." + fi + cargo nextest run --profile ci --workspace "${skip[@]}" --locked --features heif "${targets[@]}" shell: bash - name: Doctests diff --git a/scripts/ci-windows-gpu-tests.py b/scripts/ci-windows-gpu-tests.py new file mode 100644 index 0000000000..ad2f606a27 --- /dev/null +++ b/scripts/ci-windows-gpu-tests.py @@ -0,0 +1,89 @@ +"""Whether a pull request's Windows legs run photocraft-gpu's tests (.github/workflows/ci.yml). + +The Windows runners have no GPU: wgpu renders on WARP, the Direct3D 12 software rasterizer, where +photocraft-gpu's parity tests take about half of the integration leg's test time (#15247). The Linux +gate runs them on every pull request, and main runs them on Windows too, so a pull request's Windows +legs skip them unless the pull request changes something they are built from: + +- photocraft-gpu or a workspace package it depends on (any dependency kind, from `cargo metadata`, + so a new dependency is covered without editing this file); +- any file outside the workspace packages, except the documentation-only paths below. That covers + the shared build inputs (workspace manifest, lockfile, Cargo and nextest config, this workflow, + this script) and any input added later. + +Usage: ci-windows-gpu-tests.py BASE prints `true` (run them) or `false` (skip them). +""" + +import json +import subprocess +import sys + +GPU = 'photocraft-gpu' + +# Outside every workspace package and never read by a build or a test. Anything else outside the +# packages counts as related, so an unknown new input runs the tests rather than skipping them. +UNRELATED_PREFIXES = ('docs/', 'log/', 'contributors/', 'scorecard/') +UNRELATED_SUFFIXES = ('.md',) + + +def gpu_inputs(packages): + """The workspace packages photocraft-gpu is built from (itself included). + + `packages` is `cargo metadata`'s `packages` list. Raises ValueError when photocraft-gpu is not in + the workspace, so a rename cannot silently turn the selection off. + """ + names = {p['name'] for p in packages} + if GPU not in names: + raise ValueError(f'{GPU} is not a workspace package') + deps = {p['name']: {d['name'] for d in p['dependencies'] if d['name'] in names} for p in packages} + seen, todo = {GPU}, [GPU] + while todo: + for d in deps[todo.pop()]: + if d not in seen: + seen.add(d) + todo.append(d) + return seen + + +def package_dirs(packages, root): + """Each package's directory relative to the workspace root, with `/` separators.""" + root = root.replace('\\', '/').rstrip('/') + '/' + out = {} + for p in packages: + manifest = p['manifest_path'].replace('\\', '/') + if manifest.startswith(root): + rel = manifest[len(root):] + out[p['name']] = rel.rsplit('/', 1)[0] if '/' in rel else '' + return out + + +def needs_gpu_tests(changed, packages, root): + """Whether the changed files (paths relative to the workspace root) can affect the GPU tests.""" + inputs = gpu_inputs(packages) + # Longest directory first, so a nested package wins over the one around it. + dirs = sorted(((d, n) for n, d in package_dirs(packages, root).items() if d), key=lambda x: -len(x[0])) + for path in changed: + owner = next((n for d, n in dirs if path.startswith(d + '/')), None) + if owner is not None: + if owner in inputs: + return True + continue + if path.startswith(UNRELATED_PREFIXES) or path.endswith(UNRELATED_SUFFIXES): + continue + return True + return False + + +def main(argv): + if len(argv) != 2: + print(__doc__, file=sys.stderr) + return 2 + base = argv[1] + changed = subprocess.run(['git', 'diff', '--name-only', base, 'HEAD'], check=True, capture_output=True, text=True).stdout.split() + meta = json.loads(subprocess.run(['cargo', 'metadata', '--no-deps', '--format-version', '1'], check=True, capture_output=True, text=True).stdout) + print('true' if needs_gpu_tests(changed, meta['packages'], meta['workspace_root']) else 'false') + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/scripts/test-ci-windows-gpu-tests.py b/scripts/test-ci-windows-gpu-tests.py new file mode 100644 index 0000000000..abff7e47bd --- /dev/null +++ b/scripts/test-ci-windows-gpu-tests.py @@ -0,0 +1,80 @@ +import importlib.util +from pathlib import Path +import unittest + +spec = importlib.util.spec_from_file_location('gpu_select', Path(__file__).with_name('ci-windows-gpu-tests.py')) +select = importlib.util.module_from_spec(spec) +spec.loader.exec_module(select) + +ROOT = '/w' + + +def pkg(name, path, deps=()): + return {'name': name, 'manifest_path': f'{ROOT}/{path}/Cargo.toml', 'dependencies': [{'name': d} for d in deps]} + + +# gpu builds on compose (directly) and raster (through compose, and as a dev-dependency kind: +# cargo metadata lists every kind in one list); ui-egui builds on gpu, so it is not an input. +PACKAGES = [ + pkg('photocraft-raster', 'crates/raster'), + pkg('photocraft-compose', 'crates/compose', ['photocraft-raster', 'serde']), + pkg('photocraft-gpu', 'crates/gpu', ['photocraft-compose', 'wgpu']), + pkg('photocraft-ui-egui', 'crates/ui-egui', ['photocraft-gpu']), + pkg('photocraft', 'apps/photocraft', ['photocraft-ui-egui']), +] + + +def needs(*changed, packages=PACKAGES): + return select.needs_gpu_tests(list(changed), packages, ROOT) + + +class Selection(unittest.TestCase): + def test_gpu_and_what_it_builds_on_run_the_tests(self): + for path in ['crates/gpu/src/lib.rs', 'crates/gpu/tests/it/parity.rs', 'crates/compose/src/blend.rs', + 'crates/raster/Cargo.toml', 'crates/raster/build.rs']: + with self.subTest(path=path): + self.assertTrue(needs(path)) + + def test_packages_built_on_gpu_skip_them(self): + self.assertFalse(needs('crates/ui-egui/src/canvas.rs', 'apps/photocraft/src/main.rs')) + + def test_shared_build_inputs_run_them(self): + for path in ['Cargo.toml', 'Cargo.lock', '.config/nextest.toml', '.github/workflows/ci.yml', + '.cargo/config.toml', 'rust-toolchain.toml', 'scripts/ci-windows-gpu-tests.py']: + with self.subTest(path=path): + self.assertTrue(needs('crates/ui-egui/src/canvas.rs', path)) + + def test_documentation_skips_them(self): + self.assertFalse(needs('docs/development.md', 'README.md', 'crates/ui-egui/README.md', 'scorecard/ui.toml')) + + def test_unknown_files_outside_packages_run_them(self): + for path in ['assets/shaders/x.wgsl', 'scripts/other.py', 'i18n/de.tsv', 'deleted-crate/src/lib.rs']: + with self.subTest(path=path): + self.assertTrue(needs(path)) + + def test_nothing_changed_skips_them(self): + self.assertFalse(needs()) + + def test_a_nested_package_belongs_to_itself(self): + packages = PACKAGES + [pkg('photocraft-gpu-fuzz', 'crates/gpu/fuzz', ['photocraft-gpu'])] + self.assertFalse(needs('crates/gpu/fuzz/src/main.rs', packages=packages)) + self.assertTrue(needs('crates/gpu/src/lib.rs', packages=packages)) + + def test_a_new_dependency_is_followed_without_editing_the_script(self): + packages = PACKAGES + [pkg('photocraft-new', 'crates/new')] + self.assertFalse(needs('crates/new/src/lib.rs', packages=packages)) + packages[2] = pkg('photocraft-gpu', 'crates/gpu', ['photocraft-compose', 'photocraft-new']) + self.assertTrue(needs('crates/new/src/lib.rs', packages=packages)) + + def test_windows_paths_from_cargo_metadata(self): + packages = [dict(p, manifest_path=p['manifest_path'].replace('/', '\\')) for p in PACKAGES] + self.assertTrue(select.needs_gpu_tests(['crates/compose/src/blend.rs'], packages, ROOT.replace('/', '\\'))) + self.assertFalse(select.needs_gpu_tests(['crates/ui-egui/src/canvas.rs'], packages, ROOT.replace('/', '\\'))) + + def test_a_missing_gpu_package_is_an_error(self): + with self.assertRaises(ValueError): + needs('crates/ui-egui/src/canvas.rs', packages=[p for p in PACKAGES if p['name'] != 'photocraft-gpu']) + + +if __name__ == '__main__': + unittest.main()