Files
photocraft/scripts/test-ci-windows-gpu-tests.py
T
David Mann d971810daa 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.
2026-11-15 23:32:31 +01:00

81 lines
3.7 KiB
Python

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()