mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
ci: a pull request's Linux gate tests only the packages its changes reach
Part of #15711
This commit is contained in:
1 parent
c03a989f5a
commit
d5e182a725
3 files changed
+54
-3
No files matched your search
@@ -87,6 +87,8 @@ jobs:
|
||||
# Pull requests run them only when they change the GPU crate, a workspace crate it builds on, any
|
||||
# package manifest, 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.
|
||||
# `linux_skip`: the packages the Linux gate leaves out of its test build because nothing a pull request changes
|
||||
# reaches them (same rule, every package but photocraft-gpu); empty on main, the nightly run and `full-ci`.
|
||||
# `windows_skip`: the platform-neutral packages whose Windows tests a pull request skips because nothing it
|
||||
# changes reaches them (same script); empty on main and `full-ci`.
|
||||
platforms:
|
||||
@@ -98,6 +100,7 @@ jobs:
|
||||
windows: ${{ steps.pick.outputs.windows }}
|
||||
windows_gpu: ${{ steps.pick.outputs.windows_gpu }}
|
||||
windows_skip: ${{ steps.pick.outputs.windows_skip }}
|
||||
linux_skip: ${{ steps.pick.outputs.linux_skip }}
|
||||
web: ${{ steps.pick.outputs.web }}
|
||||
steps:
|
||||
- name: Harden runner
|
||||
@@ -119,6 +122,7 @@ jobs:
|
||||
echo "windows=true"
|
||||
echo "windows_gpu=true"
|
||||
echo "windows_skip="
|
||||
echo "linux_skip="
|
||||
echo "web=true"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
@@ -142,6 +146,11 @@ jobs:
|
||||
if [ "$gpu" = false ]; then
|
||||
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
|
||||
linux_skip=$(python3 scripts/ci-windows-gpu-tests.py --skip-linux "$BASE")
|
||||
echo "linux_skip=$linux_skip" >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$linux_skip" ]; then
|
||||
echo "::notice::Tests of packages the pull request does not reach are skipped on Linux (main runs them all): $linux_skip"
|
||||
fi
|
||||
skip=$(python3 scripts/ci-windows-gpu-tests.py --skip-neutral "$BASE")
|
||||
echo "windows_skip=$skip" >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$skip" ]; then
|
||||
@@ -163,7 +172,9 @@ jobs:
|
||||
# the newest one. The lint legs keep no cache (`lint-cache: false`): a cold lint leg costs
|
||||
# minutes, and their entries (~1 GB per OS) would not fit the 10 GB cache budget.
|
||||
gate:
|
||||
if: github.event.action != 'labeled' || github.event.label.name == 'full-ci'
|
||||
# `platforms` is skipped on the nightly run, which tests everything.
|
||||
needs: platforms
|
||||
if: ${{ !cancelled() && contains(fromJSON('["success", "skipped"]'), needs.platforms.result) && (github.event.action != 'labeled' || github.event.label.name == 'full-ci') }}
|
||||
# Tracks @main so suite-wide CI fixes reach every app without a PR in each repository.
|
||||
uses: storytold/craft-common-actions/.github/workflows/gate.yml@main
|
||||
with:
|
||||
@@ -184,6 +195,7 @@ jobs:
|
||||
PHOTOCRAFT_NO_PRINT=1
|
||||
LPDEST=photocraft-no-such-printer
|
||||
CARGO_PROFILE_TEST_STRIP=symbols
|
||||
PHOTOCRAFT_CI_EXCLUDE=${{ needs.platforms.outputs.linux_skip }}
|
||||
timeout-minutes: 100
|
||||
cache-workspace-crates: true
|
||||
lint-cache: false
|
||||
|
||||
@@ -20,10 +20,15 @@ any workspace package it depends on has a changed file, and nothing shared chang
|
||||
a file outside the packages that is not documentation). They have no `cfg(windows)`, `cfg(unix)` or
|
||||
`cfg(target_os ...)` in their sources, so Windows adds no coverage over the Linux gate for them.
|
||||
|
||||
The Linux gate skips by the same rule for every package except photocraft-gpu, whose tests the Linux
|
||||
gate runs on every pull request (`--skip-linux`).
|
||||
|
||||
Usage:
|
||||
ci-windows-gpu-tests.py BASE prints `true` (run photocraft-gpu's tests) or `false`.
|
||||
ci-windows-gpu-tests.py --skip-neutral BASE prints the neutral packages to skip, space-separated
|
||||
(nothing when none).
|
||||
ci-windows-gpu-tests.py --skip-linux BASE prints the packages the Linux gate skips, space-separated
|
||||
(nothing when none).
|
||||
"""
|
||||
|
||||
import json
|
||||
@@ -130,6 +135,17 @@ def neutral_to_skip(changed, packages, root):
|
||||
return sorted(n for n in NEUTRAL if n in deps and not (inputs_of(n, deps) & owners))
|
||||
|
||||
|
||||
def linux_to_skip(changed, packages, root):
|
||||
"""Every workspace package but photocraft-gpu whose tests the Linux gate skips for these changed
|
||||
files, sorted: nothing it depends on (itself included) has a changed file, and nothing shared
|
||||
changed."""
|
||||
owners = changed_packages(changed, packages, root)
|
||||
if owners is None:
|
||||
return []
|
||||
deps = workspace_deps(packages)
|
||||
return sorted(n for n in deps if n != GPU and not (inputs_of(n, deps) & owners))
|
||||
|
||||
|
||||
def changed_files(base, cwd=None):
|
||||
"""The files changed between `base` and HEAD. `--no-renames` lists both sides of a move: by
|
||||
default git names only the destination, so moving a file out of photocraft-gpu would look like a
|
||||
@@ -141,14 +157,17 @@ def changed_files(base, cwd=None):
|
||||
def main(argv):
|
||||
args = argv[1:]
|
||||
skip_neutral = args[:1] == ['--skip-neutral']
|
||||
if skip_neutral:
|
||||
skip_linux = args[:1] == ['--skip-linux']
|
||||
if skip_neutral or skip_linux:
|
||||
args = args[1:]
|
||||
if len(args) != 1:
|
||||
print(__doc__, file=sys.stderr)
|
||||
return 2
|
||||
changed = changed_files(args[0])
|
||||
meta = json.loads(subprocess.run(['cargo', 'metadata', '--no-deps', '--format-version', '1'], check=True, capture_output=True, text=True).stdout)
|
||||
if skip_neutral:
|
||||
if skip_linux:
|
||||
print(' '.join(linux_to_skip(changed, meta['packages'], meta['workspace_root'])))
|
||||
elif skip_neutral:
|
||||
print(' '.join(neutral_to_skip(changed, meta['packages'], meta['workspace_root'])))
|
||||
else:
|
||||
print('true' if needs_gpu_tests(changed, meta['packages'], meta['workspace_root']) else 'false')
|
||||
|
||||
@@ -132,5 +132,25 @@ class NeutralSelection(unittest.TestCase):
|
||||
self.assertEqual(self.skipped('docs/a.md'), ['photocraft-algo', 'photocraft-compose', 'photocraft-geom'])
|
||||
|
||||
|
||||
class TestLinuxSkip(unittest.TestCase):
|
||||
def skipped(self, *changed):
|
||||
return select.linux_to_skip(list(changed), PACKAGES, ROOT)
|
||||
|
||||
def test_a_leaf_change_skips_what_does_not_build_on_it(self):
|
||||
self.assertEqual(self.skipped('crates/ui-egui/src/lib.rs'), ['photocraft-compose', 'photocraft-raster'])
|
||||
|
||||
def test_a_change_reaches_the_packages_built_on_it_but_never_skips_gpu(self):
|
||||
self.assertEqual(self.skipped('crates/compose/src/lib.rs'), ['photocraft-raster'])
|
||||
self.assertNotIn('photocraft-gpu', self.skipped('crates/ui-egui/src/lib.rs'))
|
||||
|
||||
def test_shared_inputs_skip_nothing(self):
|
||||
for path in ['crates/raster/Cargo.toml', 'Cargo.lock', '.github/workflows/ci.yml']:
|
||||
with self.subTest(path=path):
|
||||
self.assertEqual(self.skipped('crates/ui-egui/src/lib.rs', path), [])
|
||||
|
||||
def test_documentation_only_skips_everything_but_gpu(self):
|
||||
self.assertEqual(self.skipped('docs/a.md'), ['photocraft', 'photocraft-compose', 'photocraft-raster', 'photocraft-ui-egui'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user