mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
Merge pull request #3386 from aiongg/ci-fast-next
CI: pull requests gate on the Linux Workspace legs; macOS and Windows run after the merge
This commit is contained in:
6 files changed
+88
-36
No files matched your search
@@ -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'
|
||||
|
||||
@@ -52,13 +52,22 @@ jobs:
|
||||
- uses: step-security/dtolnay-rust-toolchain@v1.0.0
|
||||
with:
|
||||
toolchain: stable
|
||||
- name: Cache the CC0 sample files
|
||||
uses: actions/cache@v6.1.0
|
||||
# Pull requests restore the entry main or next saved and never write their own: the same
|
||||
# files saved once per pull request took a share of the 10 GB cache budget.
|
||||
- name: Restore the CC0 sample files
|
||||
id: samples
|
||||
uses: actions/cache/restore@v6.1.0
|
||||
with:
|
||||
path: ${{ runner.temp }}/crw-samples
|
||||
key: crw-samples-${{ hashFiles('crates/crw/tests/samples.json') }}
|
||||
- name: Fetch the pinned CC0 sample files (raw.pixls.us)
|
||||
run: python scripts/fetch-crw-samples.py "$RUNNER_TEMP/crw-samples"
|
||||
- name: Save the CC0 sample files
|
||||
if: github.event_name != 'pull_request' && steps.samples.outputs.cache-hit != 'true'
|
||||
uses: actions/cache/save@v6.1.0
|
||||
with:
|
||||
path: ${{ runner.temp }}/crw-samples
|
||||
key: ${{ steps.samples.outputs.cache-primary-key }}
|
||||
- run: cargo test -p craft-crw --release --locked --lib -- integration::samples --nocapture
|
||||
env:
|
||||
CRAFT_CRW_SAMPLES: ${{ runner.temp }}/crw-samples
|
||||
|
||||
@@ -32,3 +32,27 @@ 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, and its Linux leg builds from source and
|
||||
# saves next's own workspace-crates cache entry, which pull requests into next restore. 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
|
||||
@@ -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
|
||||
@@ -63,10 +64,13 @@ jobs:
|
||||
# The Linux leg keeps the compiled workspace crates between runs (`cache-workspace-crates`): each
|
||||
# main run saves a rolling cache entry of its own, every run restores the newest one, and Cargo
|
||||
# rebuilds only the crates a change reaches. `cache-prune` keeps the newest entry. The midnight
|
||||
# scheduled run builds from source (`cold-build`) and starts the entry afresh. The macOS and
|
||||
# Windows legs keep a dependency-only entry: their workspace crates would not fit the 10 GB cache
|
||||
# budget beside Linux's. The lint legs keep no cache (`lint-cache: false`) for the same reason; a
|
||||
# cold lint leg is still shorter than its gate leg.
|
||||
# scheduled run builds from source (`cold-build`) and starts the entry afresh. next has an entry
|
||||
# of its own, since main's is built from different code and lockfile and a pull request into next
|
||||
# rebuilt nearly everything from it (15.5 minutes): nightly.yml's daily manual run on next builds
|
||||
# from source and saves it (`cache-save-on-dispatch`), and pull requests into next restore it
|
||||
# before main's. The macOS and Windows legs keep a dependency-only entry: their workspace crates
|
||||
# would not fit the 10 GB cache budget beside Linux's. The lint legs keep no cache
|
||||
# (`lint-cache: false`) for the same reason; a cold lint leg is still shorter than its gate leg.
|
||||
native:
|
||||
name: Workspace
|
||||
needs: platforms
|
||||
@@ -74,7 +78,8 @@ jobs:
|
||||
with:
|
||||
os: '["ubuntu-latest"]'
|
||||
cache-workspace-crates: true
|
||||
cold-build: ${{ github.event.schedule == '17 0 * * *' }}
|
||||
cache-save-on-dispatch: true
|
||||
cold-build: ${{ github.event.schedule == '17 0 * * *' || github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/next' }}
|
||||
lint-cache: false
|
||||
# The vendored crates are on the workspace `exclude` list, so unreached-rs has no module tree for them.
|
||||
unreached-rs-allow: |
|
||||
@@ -142,13 +147,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"]'
|
||||
@@ -181,14 +187,15 @@ 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
|
||||
|
||||
# Each main run's Linux leg saves a rolling cache entry of its own (`cache-workspace-crates`), and
|
||||
# every run restores only the newest. This deletes the older ones as soon as the Linux leg is
|
||||
# done, instead of leaving them to the 10 GB budget's eviction, which would evict other entries
|
||||
# too. The only job with `actions: write`; it checks out and runs nothing from the repository.
|
||||
# Each main run's Linux leg saves a rolling cache entry of its own (`cache-workspace-crates`), as
|
||||
# does the daily manual run on next, and every run restores only the newest. This deletes the
|
||||
# older ones of the run's branch as soon as the Linux leg is done, instead of leaving them to the
|
||||
# 10 GB budget's eviction, which would evict other entries too. The only job with
|
||||
# `actions: write`; it checks out and runs nothing from the repository.
|
||||
cache-prune:
|
||||
name: cache prune
|
||||
needs: native
|
||||
if: ${{ !cancelled() && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
|
||||
if: ${{ !cancelled() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/next') }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
permissions:
|
||||
@@ -202,10 +209,11 @@ jobs:
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
REF: ${{ github.ref }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# `<version>-rust-<profile>-<job>-crates-<os>-<arch>-<run>-<attempt>-...`, newest first.
|
||||
gh cache list --repo "$REPO" --ref refs/heads/main --limit 100 --sort created_at --order desc --json id,key \
|
||||
gh cache list --repo "$REPO" --ref "$REF" --limit 100 --sort created_at --order desc --json id,key \
|
||||
--jq '.[] | "\(.id) \(.key)"' > "$RUNNER_TEMP/caches"
|
||||
declare -A kept
|
||||
while read -r id key; do
|
||||
|
||||
@@ -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<prefix>[A-Za-z0-9._-]+)-\$\{\{\s*\(\s*(?P<condition>[^()]+?)\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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user