From ceded0663a58470557a482f32856b58ee15f3c91 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 24 Nov 2026 19:30:11 +0000 Subject: [PATCH] CI: pull requests gate on the Linux Workspace legs; macOS and Windows run after the merge The macOS and Windows Workspace legs take 1.5-2 hours against the Linux leg's 15-40 minutes, and every pull request waited for them. They now run on every push to main and next, on main's scheduled runs, and on a daily run on next that nightly.yml starts. A pull request that needs them before it merges gets the full-ci label. Pushes to next cancel the run they supersede, as pushes to main do. --- .github/workflows/actions.lock | 3 ++- .github/workflows/nightly.yml | 23 ++++++++++++++++++++ .github/workflows/workspace.yml | 30 ++++++++++++++------------- scripts/test-workspace-concurrency.py | 21 +++++++++++++------ scripts/test-workspace-tests.py | 5 +++-- 5 files changed, 59 insertions(+), 23 deletions(-) diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock index 66897e207..01b258e23 100644 --- a/.github/workflows/actions.lock +++ b/.github/workflows/actions.lock @@ -69,7 +69,8 @@ workflows: '.github/workflows/menu.yml': - 'actions/checkout@v7.0.1' - 'dtolnay/rust-toolchain@stable' - '.github/workflows/nightly.yml': [] + '.github/workflows/nightly.yml': + - 'step-security/harden-runner@v2.22.4' '.github/workflows/pcraft-format.yml': - 'actions/checkout@v7.0.1' - 'step-security/dtolnay-rust-toolchain@v1.0.0' diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index ed9d36127..cfdac6be1 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -32,3 +32,26 @@ jobs: cache-key: photocraft-corpus cache-key-files: scripts/ci-test-inputs.sh command: cargo nextest run --workspace --all-features --locked --profile ci + + # Pull requests run the Workspace gate's Linux legs only, and pushes to next cancel each other's + # runs, so this starts one Workspace run on next a day that nothing cancels: next's macOS and + # Windows legs then run in full at least once a day. Main gets the same from workspace.yml's own + # scheduled runs. The only job here with `actions: write`; it checks out and runs nothing from + # the repository. + workspace-next: + name: Workspace on next + if: github.event_name == 'schedule' + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + actions: write + steps: + - name: Harden runner + uses: step-security/harden-runner@v2.22.4 + with: + egress-policy: audit + - name: Start the Workspace workflow on next + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + run: gh workflow run workspace.yml --repo "$REPO" --ref next diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index c583402a5..1bd5c108e 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -16,19 +16,20 @@ permissions: contents: read concurrency: - # A pull request, and main, each have one group, so a newer push cancels the run it supersedes; - # the newest push's run still tests everything before it. Every other run (a release tag, a - # manual run, the scheduled run) gets a group of its own and is neither cancelled nor replaced - # while queued: a release run always finishes, and the scheduled run saves the caches. - group: workspace-${{ (github.event_name == 'pull_request' || github.event_name == 'push' && github.ref == 'refs/heads/main') && github.ref || github.run_id }} - cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'push' && github.ref == 'refs/heads/main' }} + # A pull request, main and next each have one group, so a newer push cancels the run it + # supersedes; the newest push's run still tests everything before it. Every other run (a release + # tag, a manual run, the scheduled run, nightly.yml's run on next) gets a group of its own and is + # neither cancelled nor replaced while queued: a release run always finishes, the scheduled run + # saves the caches, and next gets one complete macOS and Windows run a day. + group: workspace-${{ (github.event_name == 'pull_request' || github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'push' && github.ref == 'refs/heads/next') && github.ref || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' || github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'push' && github.ref == 'refs/heads/next' }} jobs: # Whether this run needs the macOS and Windows legs, and which tests every leg runs - # (craft-common-actions' select-platforms). On a pull request the macOS and Windows legs run only - # when it can change platform behaviour: a crate with platform cfg code or one that depends on - # it, the build setup, or a file outside the crates. The tests are those of the crates a change - # reaches: the crates that own a changed file, the crates whose Cargo.toml declares a read of it + # (craft-common-actions' select-platforms). A pull request runs the Linux legs only, unless it + # has the full-ci label (see native-platforms); every other event runs the macOS and Windows legs + # too. The tests are those of the crates a change reaches: the crates that own a changed file, + # the crates whose Cargo.toml declares a read of it # (`[package.metadata.craft] reads`, which this job checks is complete), and every crate that # depends on those. The build setup, a crate's own Cargo.toml or a file outside the crates other # than documentation runs every test; documentation alone runs none. The full-ci label runs @@ -142,13 +143,14 @@ jobs: cargo test --workspace --doc --all-features --locked cargo nextest run -p craft-image-codecs -p craft-text --locked --profile ci -E "$CRAFT_TEST_FILTER" --no-tests=warn --lib --bins --tests - # The macOS and Windows legs, when `platforms` says this run needs them, with the Linux leg's - # inputs. + # The macOS and Windows legs, with the Linux leg's inputs. They take 1.5-2 hours against the Linux + # leg's 15-40 minutes, so a pull request does not wait for them: they run after the merge, on + # every push to main and next, on main's scheduled runs and on nightly.yml's daily run on next. + # A pull request that needs them before it merges gets the full-ci label. native-platforms: name: Workspace needs: platforms - # Pushes to next run Linux only. - if: needs.platforms.outputs.platform == 'true' && github.ref != 'refs/heads/next' + if: needs.platforms.outputs.platform == 'true' && (github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'full-ci')) uses: storytold/craft-common-actions/.github/workflows/gate.yml@main with: os: '["windows-latest","macos-latest"]' diff --git a/scripts/test-workspace-concurrency.py b/scripts/test-workspace-concurrency.py index db20031e9..b8324eb0a 100644 --- a/scripts/test-workspace-concurrency.py +++ b/scripts/test-workspace-concurrency.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -"""Check the Workspace workflow's cancellation policy: pull requests and pushes to main cancel the -run they supersede; release tags, manual runs and scheduled runs are never cancelled. +"""Check the Workspace workflow's cancellation policy: pull requests and pushes to main or next +cancel the run they supersede; release tags, manual runs and scheduled runs are never cancelled. The policy is the top-level `concurrency` block of .github/workflows/workspace.yml. This script reads those fields, requires the documented expression shapes, and checks which group each event @@ -29,7 +29,11 @@ PULL_REQUEST, PUSH, DISPATCH, SCHEDULE = "pull_request", "push", "workflow_dispa # false". This exact condition is the whole of the expression language this script understands, so # a reworded policy has to be reworded here too, on purpose. github.ref, never github.head_ref or # github.sha. -SUPERSEDED = "github.event_name == 'pull_request' || github.event_name == 'push' && github.ref == 'refs/heads/main'" +SUPERSEDED = ( + "github.event_name == 'pull_request'" + " || github.event_name == 'push' && github.ref == 'refs/heads/main'" + " || github.event_name == 'push' && github.ref == 'refs/heads/next'" +) GROUP_SHAPE = re.compile( r"(?P[A-Za-z0-9._-]+)-\$\{\{\s*\(\s*(?P[^()]+?)\s*\)\s*" r"&&\s*github\.ref\s*\|\|\s*github\.run_id\s*\}\}" @@ -43,7 +47,7 @@ def normal(expression): def superseded(event_name, ref): """SUPERSEDED, evaluated.""" - return event_name == PULL_REQUEST or (event_name == PUSH and ref == "refs/heads/main") + return event_name == PULL_REQUEST or (event_name == PUSH and ref in ("refs/heads/main", "refs/heads/next")) def read_concurrency(text): @@ -82,10 +86,11 @@ def other_run(event_name, ref, run_id): return (event_name, ref, run_id) -MAIN, TAG = ("refs/heads/main", "refs/tags/v1.2.3") +MAIN, NEXT, TAG = ("refs/heads/main", "refs/heads/next", "refs/tags/v1.2.3") SAME_GROUP = [ ("a newer commit on the same pull request", pull_request(1316, 43599251877), pull_request(1316, 43600899878)), ("two pushes to main", other_run(PUSH, MAIN, 3), other_run(PUSH, MAIN, 4)), + ("two pushes to next", other_run(PUSH, NEXT, 20), other_run(PUSH, NEXT, 21)), ] DIFFERENT_GROUPS = [ ("two pull requests", pull_request(1316, 1), pull_request(1317, 1)), @@ -96,11 +101,15 @@ DIFFERENT_GROUPS = [ ("a main push and a scheduled run", other_run(PUSH, MAIN, 17), other_run(SCHEDULE, MAIN, 17)), ("a main push and a manual run of main", other_run(PUSH, MAIN, 18), other_run(DISPATCH, MAIN, 18)), ("a main push and a pull request", other_run(PUSH, MAIN, 9), pull_request(1316, 9)), + ("a main push and a next push", other_run(PUSH, MAIN, 22), other_run(PUSH, NEXT, 22)), + ("a next push and the nightly manual run of next", other_run(PUSH, NEXT, 23), other_run(DISPATCH, NEXT, 23)), ("a release tag and a pull request", other_run(PUSH, TAG, 10), pull_request(1316, 10)), ] CANCELLATION = [ ("a push supersedes the previous run of its pull request", pull_request(1316, 11), True), ("a push to main supersedes the previous main run", other_run(PUSH, MAIN, 12), True), + ("a push to next supersedes the previous next run", other_run(PUSH, NEXT, 24), True), + ("the nightly manual run of next is never cancelled", other_run(DISPATCH, NEXT, 25), False), ("a release tag run is never cancelled", other_run(PUSH, TAG, 13), False), ("a manual run is never cancelled", other_run(DISPATCH, MAIN, 14), False), ("the scheduled run that saves the caches is never cancelled", other_run(SCHEDULE, MAIN, 19), False), @@ -149,7 +158,7 @@ class ConcurrencyTests(unittest.TestCase): with self.subTest(description): self.assertNotEqual(self.group(*first), self.group(*second), description) - def test_only_pull_requests_and_main_pushes_cancel(self): + def test_only_pull_requests_and_main_and_next_pushes_cancel(self): for description, context, expected in CANCELLATION: with self.subTest(description): self.assertEqual(self.cancels(context[0], context[1]), expected, description) diff --git a/scripts/test-workspace-tests.py b/scripts/test-workspace-tests.py index 72772c0f7..c2d0b82e9 100644 --- a/scripts/test-workspace-tests.py +++ b/scripts/test-workspace-tests.py @@ -230,8 +230,9 @@ class WorkspaceTests(unittest.TestCase): self.assertIn('os: \'["ubuntu-latest"]\'', source) self.assertIn('os: \'["windows-latest","macos-latest"]\'', source) self.assertIn("if: needs.platforms.outputs.platform == 'true'", source) - # Pushes to next run Linux only. - self.assertIn("&& github.ref != 'refs/heads/next'", source) + # Pull requests run Linux only, unless labelled full-ci; every other event runs every leg. + self.assertIn("&& (github.event_name != 'pull_request'" + " || contains(github.event.pull_request.labels.*.name, 'full-ci'))", source) # Every leg reads the test selection of the platforms job. self.assertIn(" native:\n name: Workspace\n needs: platforms\n", source) self.assertIn(" select-tests: true\n", source)