mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-20 17:06:42 +00:00
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.
90 lines
3.7 KiB
Python
90 lines
3.7 KiB
Python
"""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))
|