mirror of
https://github.com/storytold/craft-common-actions.git
synced 2026-12-01 10:51:35 +01:00
gate: build the tests once per runner and keep workspace crates in a rolling cache entry
With archive-command, a build (<os>) job per runner builds the tests once into a nextest archive; the shard legs download it and build nothing, and only they wait for the build job. after-archive-command runs in the build job after the upload. With cache-workspace-crates, the saving leg writes a rolling dependency entry that keeps the workspace crates, and every leg restores the newest one with restore-mtimes. The lint legs move to a lint job of their own that never waits for the build. Every job's setup is actions/gate-setup; commands run through actions/gate-run. Every new input defaults to today's behaviour. The save-condition guards read the cache-save and writes inputs every job passes to gate-setup: the build and lint jobs carry the approved condition, the gate job the same narrowed to its one saving leg per runner. Result markers are files named after their leg and download with merge-multiple, so one shard or one build lands where the check reads it. The archive upload overwrites on a re-run. archive-command without test-shards is an error. The first-party actions are pinned to the commit that added gate-setup.
This commit is contained in:
1 parent
7513b173b4
commit
528446563c
6 files changed
+681
-380
No files matched your search
+296
-239
@@ -3,7 +3,9 @@ name: "Gate"
|
||||
# The quality gate the craft apps run on pull requests and pushes to main: one job per runner in
|
||||
# `os`, each running `command` (by default `cargo xtask ci`) with the suite's shared setup, and with
|
||||
# `lint-command` a second job per runner that runs the lint checks beside it. With `test-shards`,
|
||||
# each runner runs its tests as that many shard jobs instead of one.
|
||||
# each runner runs its tests as that many shard jobs instead of one, and with `archive-command` a
|
||||
# `build (<os>)` job builds the tests once for all of them. The setup every job shares is
|
||||
# actions/gate-setup; each job's command runs through actions/gate-run.
|
||||
# App-specific checks (fuzzing, corpora, web builds) belong here too, as shared workflows or
|
||||
# inputs: an app's workflows only call this repository's workflows.
|
||||
on:
|
||||
@@ -30,7 +32,7 @@ on:
|
||||
required: false
|
||||
default: ""
|
||||
warm-command:
|
||||
description: "Optional build that fills the dependency cache, for example `cargo test --workspace --no-run --locked`; empty (default) runs none. Where the dependency cache saves, a `cache warm (<os>)` leg beside the gate runs it and saves the `gate` entry as soon as it succeeds, so a failing test no longer keeps the entry from being saved. Give it the build the gate does (same features, profile and targets) and nothing else; the gate legs then only restore"
|
||||
description: "Optional build that fills the dependency cache, for example `cargo test --workspace --no-run --locked`; empty (default) runs none. Where the dependency cache saves, a `cache warm (<os>)` leg beside the gate runs it and saves the `gate` entry as soon as it succeeds, so a failing test no longer keeps the entry from being saved. Give it the build the gate does (same features, profile and targets) and nothing else; the gate legs then only restore. With archive-command the build job saves the entry, and no warm leg runs"
|
||||
type: string
|
||||
required: false
|
||||
default: ""
|
||||
@@ -70,7 +72,22 @@ on:
|
||||
required: false
|
||||
default: 0
|
||||
shard-command:
|
||||
description: "With test-shards: each shard leg's command, which builds and runs its share of the tests. `GATE_SHARD` (1..N), `GATE_SHARDS` (N) and `NEXTEST_PARTITION` (`hash:<k>/<N>`) say which share, for example `cargo nextest run --workspace --locked --partition \"$NEXTEST_PARTITION\"`"
|
||||
description: "With test-shards: each shard leg's command, which builds and runs its share of the tests (with archive-command, runs it from the archive at $NEXTEST_ARCHIVE_FILE). `GATE_SHARD` (1..N), `GATE_SHARDS` (N) and `NEXTEST_PARTITION` (`hash:<k>/<N>`) say which share, for example `cargo nextest run --workspace --locked --partition \"$NEXTEST_PARTITION\"`"
|
||||
type: string
|
||||
required: false
|
||||
default: ""
|
||||
archive-command:
|
||||
description: "With test-shards: build the tests once per runner, in a `build (<os>)` job that runs this command to write a nextest archive to $NEXTEST_ARCHIVE_FILE. The shard legs download the archive instead of building, and only they wait for the build job. Where the dependency cache saves, the build job saves the `gate` entry. A failed build skips the shards of every runner in the call, so give each runner a call of its own. Empty (default): each shard builds its own tests; test-shards: 0 with an archive-command is an error"
|
||||
type: string
|
||||
required: false
|
||||
default: ""
|
||||
archive-file:
|
||||
description: "File name of the archive archive-command writes, in the runner's temporary directory"
|
||||
type: string
|
||||
required: false
|
||||
default: "nextest-archive.tar.zst"
|
||||
after-archive-command:
|
||||
description: "With archive-command: a command the build job runs after it has uploaded the archive, for checks that need the build directory (doctests, say). The shards wait for the whole build job, so its time adds to the gate's. `gate (<os>)` passes only when it passed too. Empty runs none"
|
||||
type: string
|
||||
required: false
|
||||
default: ""
|
||||
@@ -176,6 +193,16 @@ on:
|
||||
required: false
|
||||
# Same default as actions/rust-cache, which explains the v2 bump.
|
||||
default: "v2"
|
||||
cache-workspace-crates:
|
||||
description: "Keep the workspace crates' compiled libraries and unit-test executables in the dependency cache as a rolling entry: the leg that saves writes an entry of its own each run, every leg restores the newest one, and actions/restore-mtimes resets source mtimes from the diff against the commit that entry was built from, so Cargo rebuilds only what changed. The lint legs keep their usual entry"
|
||||
type: boolean
|
||||
required: false
|
||||
default: false
|
||||
cold-build:
|
||||
description: "With cache-workspace-crates: restore no dependency cache and build everything from source; where the cache saves, the saving leg still writes a fresh entry (a nightly cold run is the safety net for the restored mtimes, and it starts the rolling entry afresh)"
|
||||
type: boolean
|
||||
required: false
|
||||
default: false
|
||||
cache-save-on-dispatch:
|
||||
description: "Allow manually dispatched branch runs to save their branch-scoped dependency cache; pull requests never write"
|
||||
type: boolean
|
||||
@@ -200,7 +227,7 @@ jobs:
|
||||
# in `os`.
|
||||
select:
|
||||
name: select legs
|
||||
if: (inputs.select-os != '' && inputs.select-os != '[]') || inputs.test-shards != 0
|
||||
if: (inputs.select-os != '' && inputs.select-os != '[]') || inputs.test-shards != 0 || inputs.archive-command != ''
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 5
|
||||
outputs:
|
||||
@@ -220,24 +247,28 @@ jobs:
|
||||
fetch-depth: 2
|
||||
- id: select
|
||||
if: inputs.select-os != '' && inputs.select-os != '[]'
|
||||
uses: storytold/craft-common-actions/actions/select-platforms@139cccb97f9dc462b56f39ee2830718aaa782fed
|
||||
uses: storytold/craft-common-actions/actions/select-platforms@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
os: ${{ inputs.os }}
|
||||
select-os: ${{ inputs.select-os }}
|
||||
paths: ${{ inputs.select-paths }}
|
||||
crates: ${{ inputs.select-crates }}
|
||||
label: ${{ inputs.select-label }}
|
||||
# The gate job's `shard` dimension, and the lint and warm legs it must not repeat: those
|
||||
# keep one leg per runner, as shard 1.
|
||||
# The gate job's `shard` dimension, and the warm leg it must not repeat: that keeps one leg
|
||||
# per runner, as shard 1.
|
||||
- name: Shards
|
||||
id: shards
|
||||
if: inputs.test-shards != 0
|
||||
if: inputs.test-shards != 0 || inputs.archive-command != ''
|
||||
shell: bash
|
||||
env:
|
||||
SHARDS: ${{ inputs.test-shards }}
|
||||
SHARD: ${{ inputs.shard-command }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ "$SHARDS" = 0 ]; then
|
||||
echo "::error::archive-command needs test-shards: the shard legs are what run its archive"
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! "$SHARDS" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "::error::test-shards must be 0 or a positive whole number, got '$SHARDS'"
|
||||
exit 1
|
||||
@@ -248,37 +279,33 @@ jobs:
|
||||
fi
|
||||
exclude=
|
||||
for shard in $(seq 2 "$SHARDS"); do
|
||||
exclude+="${exclude:+,}{\"part\":\"lint\",\"shard\":$shard},{\"part\":\"warm\",\"shard\":$shard}"
|
||||
exclude+="${exclude:+,}{\"part\":\"warm\",\"shard\":$shard}"
|
||||
done
|
||||
echo "shards=[$(seq -s, 1 "$SHARDS")]" >> "$GITHUB_OUTPUT"
|
||||
echo "exclude=[$exclude]" >> "$GITHUB_OUTPUT"
|
||||
|
||||
gate:
|
||||
# With archive-command: the tests are built once per runner into a nextest archive, which the
|
||||
# shard legs download instead of building. Where the dependency cache saves, this job saves the
|
||||
# gate's entry (and, with cache-workspace-crates, records the commit the entry was built from).
|
||||
build:
|
||||
needs: select
|
||||
# A skipped select (no select-os, no test-shards) still runs the gate; a failed one does not.
|
||||
if: ${{ !cancelled() && needs.select.result != 'failure' }}
|
||||
# The test part keeps the `gate (<os>)` check name callers already know. With test-shards the
|
||||
# shard legs take its place, and the `result` job reports `gate (<os>)`.
|
||||
name: ${{ matrix.part == 'lint' && 'lint' || matrix.part == 'warm' && 'cache warm' || matrix.part == 'shard' && format('test {0}/{1}', matrix.shard, inputs.test-shards) || 'gate' }} (${{ matrix.os }})
|
||||
# A skipped select (no select-os) still runs the build; a failed one does not.
|
||||
if: ${{ !cancelled() && needs.select.result != 'failure' && inputs.test-shards != 0 && inputs.archive-command != '' }}
|
||||
name: build (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: ${{ inputs.timeout-minutes }}
|
||||
strategy:
|
||||
# A failing leg must not cancel the others and hide their failures.
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: ${{ fromJSON(needs.select.outputs.os || inputs.os) }}
|
||||
# One job definition for every part, so the shared setup is written once.
|
||||
part: ${{ fromJSON(format('["{0}"{1}{2}]', inputs.test-shards != 0 && 'shard' || 'test', inputs.lint-command != '' && ',"lint"' || '', inputs.warm-command != '' && github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) && ',"warm"' || '')) }}
|
||||
# With test-shards, 1..N for the shard part; lint and warm run once, as shard 1. Otherwise 0.
|
||||
shard: ${{ fromJSON(needs.select.outputs.shards || '[0]') }}
|
||||
exclude: ${{ fromJSON(needs.select.outputs.exclude || '[]') }}
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_NET_RETRY: 10
|
||||
RUST_BACKTRACE: 1
|
||||
steps:
|
||||
- name: Harden runner
|
||||
- &harden-runner
|
||||
name: Harden runner
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
with:
|
||||
egress-policy: audit
|
||||
@@ -314,198 +341,233 @@ jobs:
|
||||
security.ubuntu.com:443
|
||||
static.crates.io:443
|
||||
static.rust-lang.org:443
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Check out craft-fonts
|
||||
if: inputs.craft-fonts-ref != ''
|
||||
- &checkout
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
repository: storytold/craft-fonts
|
||||
ref: ${{ inputs.craft-fonts-ref }}
|
||||
path: craft-fonts
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build with craft-fonts
|
||||
if: inputs.craft-fonts-ref != ''
|
||||
shell: bash
|
||||
env:
|
||||
CRAFT_FONTS_DIR: ${{ github.workspace }}/craft-fonts
|
||||
REQUIRED: ${{ inputs.require-craft-fonts }}
|
||||
run: |
|
||||
echo "CRAFT_FONTS_DIR=$CRAFT_FONTS_DIR" >> "$GITHUB_ENV"
|
||||
if [ "$REQUIRED" = true ]; then echo "CRAFT_FONTS_REQUIRED=1" >> "$GITHUB_ENV"; fi
|
||||
|
||||
# Does nothing unless the repository has craft-i18n.rev; then builds require the translations.
|
||||
- name: Check out craft-i18n
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-i18n@139cccb97f9dc462b56f39ee2830718aaa782fed
|
||||
|
||||
# Before the cache step: rust-cache keys on CARGO_* and RUST* variables.
|
||||
- name: Caller environment
|
||||
if: inputs.env != '' || inputs.linux-env != '' || inputs.windows-env != '' || inputs.dev-debug != '' || inputs.dev-strip
|
||||
shell: bash
|
||||
env:
|
||||
ALL: ${{ inputs.env }}
|
||||
LINUX: ${{ inputs.linux-env }}
|
||||
WINDOWS: ${{ inputs.windows-env }}
|
||||
DEV_DEBUG: ${{ inputs.dev-debug }}
|
||||
DEV_STRIP: ${{ inputs.dev-strip }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
case "$RUNNER_OS" in
|
||||
Linux) extra=$LINUX ;;
|
||||
Windows) extra=$WINDOWS ;;
|
||||
*) extra= ;;
|
||||
esac
|
||||
if [ -n "$DEV_DEBUG" ]; then echo "CARGO_PROFILE_DEV_DEBUG=$DEV_DEBUG" >> "$GITHUB_ENV"; fi
|
||||
if [ "$DEV_STRIP" = true ]; then
|
||||
echo "CARGO_PROFILE_TEST_DEBUG=0" >> "$GITHUB_ENV"
|
||||
echo "CARGO_PROFILE_TEST_STRIP=symbols" >> "$GITHUB_ENV"
|
||||
fi
|
||||
printf '%s\n%s\n' "$ALL" "$extra" | while IFS= read -r line; do
|
||||
[ -n "$line" ] || continue
|
||||
if ! [[ "$line" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; then
|
||||
echo "::error::env: expected KEY=VALUE, got '$line'"
|
||||
exit 1
|
||||
fi
|
||||
echo "$line" >> "$GITHUB_ENV"
|
||||
done
|
||||
|
||||
# Nothing waits on it: the space is free before the build needs it.
|
||||
- name: Free disk space
|
||||
if: runner.os == 'Linux' && inputs.free-disk-space
|
||||
run: |
|
||||
nohup sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc /usr/local/.ghcup \
|
||||
/opt/hostedtoolcache/CodeQL </dev/null >/dev/null 2>&1 &
|
||||
|
||||
- name: Install Linux build dependencies
|
||||
if: runner.os == 'Linux' && inputs.packages != ''
|
||||
uses: storytold/craft-common-actions/actions/install-apt-packages@139cccb97f9dc462b56f39ee2830718aaa782fed
|
||||
# Default-branch writes remain the default. Maintainers can explicitly opt manual branch runs
|
||||
# into branch-scoped writes; pull-request runs never save a cache.
|
||||
- name: Setup
|
||||
uses: storytold/craft-common-actions/actions/gate-setup@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
craft-fonts-ref: ${{ inputs.craft-fonts-ref }}
|
||||
require-craft-fonts: ${{ inputs.require-craft-fonts }}
|
||||
env: ${{ inputs.env }}
|
||||
linux-env: ${{ inputs.linux-env }}
|
||||
windows-env: ${{ inputs.windows-env }}
|
||||
dev-debug: ${{ inputs.dev-debug }}
|
||||
dev-strip: ${{ inputs.dev-strip }}
|
||||
free-disk-space: ${{ inputs.free-disk-space }}
|
||||
packages: ${{ inputs.packages }}
|
||||
|
||||
# The channel in rust-toolchain.toml wins over `toolchain`, so the gate builds with the
|
||||
# toolchain contributors use and a new Rust release does not invalidate the cache.
|
||||
- name: Install Rust
|
||||
shell: bash
|
||||
env:
|
||||
TOOLCHAIN: ${{ inputs.toolchain }}
|
||||
TARGETS: ${{ inputs.targets }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -f rust-toolchain.toml ]; then
|
||||
channel=$(sed -n 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' rust-toolchain.toml)
|
||||
TOOLCHAIN=${channel:-$TOOLCHAIN}
|
||||
fi
|
||||
args=(--profile minimal --no-self-update --component clippy --component rustfmt)
|
||||
for target in ${TARGETS//,/ }; do args+=(--target "$target"); done
|
||||
rustup toolchain install "$TOOLCHAIN" "${args[@]}"
|
||||
rustup default "$TOOLCHAIN"
|
||||
rustc --version
|
||||
|
||||
- name: Install cargo tools
|
||||
if: inputs.tools != ''
|
||||
uses: step-security/taiki-e-install-action@76747d22a7567cc4438546a84f11bdf18e670ab8 # v2.87.32
|
||||
with:
|
||||
tool: ${{ inputs.tools }}
|
||||
|
||||
# Default-branch writes remain the default. Maintainers can explicitly opt manual
|
||||
# branch runs into branch-scoped writes; pull-request runs never save a cache. The key
|
||||
# (the canonical root [profile] table included) lives in the shared action, so an app job
|
||||
# that builds the same workspace restores this entry instead of copying the formula.
|
||||
# No save on failure: a main run that fails at fmt or clippy has not built the test
|
||||
# profile, and rust-cache never replaces an exact-key entry, so that half-filled entry
|
||||
# would be restored by every run until Cargo.lock changes.
|
||||
# The lint part builds in check mode, so it keeps an entry of its own (`<profile>-lint`)
|
||||
# instead of racing the test part for the `gate` entry. Shard legs restore the test part's
|
||||
# entry, and shard 1 alone saves it, so the shards do not race each other for it.
|
||||
- uses: storytold/craft-common-actions/actions/rust-cache@139cccb97f9dc462b56f39ee2830718aaa782fed
|
||||
with:
|
||||
toolchain: ${{ inputs.toolchain }}
|
||||
targets: ${{ inputs.targets }}
|
||||
tools: ${{ inputs.tools }}
|
||||
cache-version: ${{ inputs.cache-version }}
|
||||
job: ${{ matrix.part == 'lint' && 'lint' || inputs.cache-name != '' && format('gate-{0}', inputs.cache-name) || '' }}
|
||||
save-if: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) && (matrix.part == 'lint' || matrix.part == 'warm' || inputs.warm-command == '' && matrix.shard <= 1) }}
|
||||
cache-on-failure: "false"
|
||||
cache-job: ${{ inputs.cache-name != '' && format('gate-{0}', inputs.cache-name) || 'gate' }}
|
||||
cache-save: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) }}
|
||||
cache-workspace-crates: ${{ inputs.cache-workspace-crates }}
|
||||
cold-build: ${{ inputs.cold-build }}
|
||||
sccache: ${{ inputs.sccache }}
|
||||
writes: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) }}
|
||||
cache-paths: ${{ inputs.cache-paths }}
|
||||
cache-key: ${{ inputs.cache-key }}
|
||||
cache-key-files: ${{ inputs.cache-key-files }}
|
||||
setup-command: ${{ inputs.setup-command }}
|
||||
|
||||
# After rust-cache, so its key does not depend on RUSTC_WRAPPER.
|
||||
- name: Install sccache
|
||||
if: inputs.sccache
|
||||
uses: Mozilla-Actions/sccache-action@fc920bf0ec8de6ee65d409111f7ec508035751ba # v0.0.11
|
||||
with:
|
||||
version: v0.18.0
|
||||
|
||||
- name: Use sccache
|
||||
if: inputs.sccache
|
||||
- name: Archive path
|
||||
shell: bash
|
||||
env:
|
||||
WRITES: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) }}
|
||||
# sccache leaves `--check-cfg` out of its key, so after a change to the expected cfgs a
|
||||
# cached compile would replay its old `unexpected_cfgs` warnings. A change to the files
|
||||
# that declare them (Cargo.toml lints, build scripts), or to cache-version, starts a
|
||||
# fresh sccache cache instead.
|
||||
VERSION: ${{ inputs.cache-version }}-${{ hashFiles('**/Cargo.toml', '**/build.rs') }}
|
||||
run: |
|
||||
echo "SCCACHE_GHA_ENABLED=true" >> "$GITHUB_ENV"
|
||||
echo "RUSTC_WRAPPER=sccache" >> "$GITHUB_ENV"
|
||||
if [ -z "${SCCACHE_GHA_VERSION:-}" ]; then
|
||||
echo "SCCACHE_GHA_VERSION=$VERSION" >> "$GITHUB_ENV"
|
||||
fi
|
||||
if [ -z "${SCCACHE_GHA_RW_MODE:-}" ] && [ "$WRITES" != true ]; then
|
||||
echo "SCCACHE_GHA_RW_MODE=READ_ONLY" >> "$GITHUB_ENV"
|
||||
fi
|
||||
FILE: ${{ runner.temp }}/${{ inputs.archive-file }}
|
||||
run: echo "NEXTEST_ARCHIVE_FILE=$FILE" >> "$GITHUB_ENV"
|
||||
|
||||
# Data the caller's setup fetches (test corpora, fixtures), keyed on the caller's pins. The
|
||||
# key is fixed by those pins, so one entry stays valid until a pin moves.
|
||||
- name: Caller cache key
|
||||
id: caller-key
|
||||
if: inputs.cache-paths != '' && matrix.part != 'lint'
|
||||
- name: Build the test archive
|
||||
uses: storytold/craft-common-actions/actions/gate-run@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
command: ${{ inputs.archive-command }}
|
||||
timeout-minutes: ${{ inputs.gate-timeout-minutes }}
|
||||
|
||||
# The marker is saved with the cache entry in rust-cache's post step.
|
||||
- name: Record the cache commit
|
||||
if: inputs.cache-workspace-crates
|
||||
uses: storytold/craft-common-actions/actions/restore-mtimes@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
mode: record
|
||||
|
||||
# A build that changed Cargo.lock ran against a lockfile that is not the one in the repository.
|
||||
- name: Lockfile unchanged
|
||||
shell: bash
|
||||
run: git diff --exit-code -- Cargo.lock
|
||||
|
||||
- name: Archive size
|
||||
shell: bash
|
||||
run: ls -l "$NEXTEST_ARCHIVE_FILE"
|
||||
|
||||
# Uncompressed: a zstd archive barely shrinks, and level 0 uploads it in seconds.
|
||||
- name: Upload the test archive
|
||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
with:
|
||||
name: gate-archive-${{ matrix.os }}
|
||||
path: ${{ runner.temp }}/${{ inputs.archive-file }}
|
||||
if-no-files-found: error
|
||||
# A re-run of the build job replaces the archive of the attempt before.
|
||||
overwrite: true
|
||||
compression-level: 0
|
||||
retention-days: 1
|
||||
|
||||
- name: After the archive
|
||||
if: inputs.after-archive-command != ''
|
||||
uses: storytold/craft-common-actions/actions/gate-run@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
command: ${{ inputs.after-archive-command }}
|
||||
timeout-minutes: ${{ inputs.gate-timeout-minutes }}
|
||||
|
||||
# The `result` job reads it: the build job's result covers every runner.
|
||||
- name: Record the build's result
|
||||
if: always()
|
||||
shell: bash
|
||||
env:
|
||||
KEY: ${{ inputs.cache-key }}
|
||||
FILES: ${{ inputs.cache-key-files }}
|
||||
FILES_HASH: ${{ inputs.cache-key-files != '' && hashFiles(inputs.cache-key-files) || '' }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "$KEY" ]; then
|
||||
echo "::error::cache-paths needs a cache-key naming the pins of what it holds"
|
||||
exit 1
|
||||
fi
|
||||
if [ -n "$FILES" ] && [ -z "$FILES_HASH" ]; then
|
||||
echo "::error::cache-key-files matches no file: $FILES"
|
||||
exit 1
|
||||
fi
|
||||
echo "key=gate-caller-$KEY${FILES_HASH:+-$FILES_HASH}" >> "$GITHUB_OUTPUT"
|
||||
RESULT: ${{ runner.temp }}/gate-result/gate-build-${{ matrix.os }}
|
||||
STATUS: ${{ job.status }}
|
||||
run: mkdir -p "$(dirname "$RESULT")" && echo "$STATUS" > "$RESULT"
|
||||
|
||||
- name: Restore caller cache
|
||||
id: caller-cache
|
||||
if: inputs.cache-paths != '' && matrix.part != 'lint'
|
||||
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5
|
||||
- name: Upload the build's result
|
||||
if: always()
|
||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
with:
|
||||
path: ${{ inputs.cache-paths }}
|
||||
key: ${{ steps.caller-key.outputs.key }}
|
||||
enableCrossOsArchive: true
|
||||
name: gate-build-${{ matrix.os }}
|
||||
path: ${{ runner.temp }}/gate-result/gate-build-${{ matrix.os }}
|
||||
if-no-files-found: error
|
||||
overwrite: true
|
||||
retention-days: 1
|
||||
|
||||
- name: Caller setup
|
||||
if: inputs.setup-command != '' && matrix.part != 'lint'
|
||||
# With lint-command: one `lint (<os>)` leg per runner beside the gate's legs, off their critical
|
||||
# path. It builds in check mode, so it keeps a dependency-cache entry of its own (`lint`), skips
|
||||
# setup-command and the caller cache, and never waits for the build job.
|
||||
lint:
|
||||
needs: select
|
||||
if: ${{ !cancelled() && needs.select.result != 'failure' && inputs.lint-command != '' }}
|
||||
name: lint (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: ${{ inputs.timeout-minutes }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: ${{ fromJSON(needs.select.outputs.os || inputs.os) }}
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_NET_RETRY: 10
|
||||
RUST_BACKTRACE: 1
|
||||
steps:
|
||||
- *harden-runner
|
||||
- *checkout
|
||||
|
||||
- name: Setup
|
||||
uses: storytold/craft-common-actions/actions/gate-setup@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
craft-fonts-ref: ${{ inputs.craft-fonts-ref }}
|
||||
require-craft-fonts: ${{ inputs.require-craft-fonts }}
|
||||
env: ${{ inputs.env }}
|
||||
linux-env: ${{ inputs.linux-env }}
|
||||
windows-env: ${{ inputs.windows-env }}
|
||||
dev-debug: ${{ inputs.dev-debug }}
|
||||
dev-strip: ${{ inputs.dev-strip }}
|
||||
free-disk-space: ${{ inputs.free-disk-space }}
|
||||
packages: ${{ inputs.packages }}
|
||||
toolchain: ${{ inputs.toolchain }}
|
||||
targets: ${{ inputs.targets }}
|
||||
tools: ${{ inputs.tools }}
|
||||
cache-version: ${{ inputs.cache-version }}
|
||||
cache-job: lint
|
||||
cache-save: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) }}
|
||||
sccache: ${{ inputs.sccache }}
|
||||
writes: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) }}
|
||||
caller-setup: "false"
|
||||
|
||||
- name: Gate
|
||||
uses: storytold/craft-common-actions/actions/gate-run@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
command: ${{ inputs.lint-command }}
|
||||
timeout-minutes: ${{ inputs.gate-timeout-minutes }}
|
||||
|
||||
- name: Lockfile unchanged
|
||||
shell: bash
|
||||
run: git diff --exit-code -- Cargo.lock
|
||||
|
||||
gate:
|
||||
needs: [select, build]
|
||||
# A skipped select (no select-os, no test-shards) or build (no archive-command) still runs the
|
||||
# gate; a failed one does not.
|
||||
if: ${{ !cancelled() && needs.select.result != 'failure' && needs.build.result != 'failure' && needs.build.result != 'cancelled' }}
|
||||
# The test part keeps the `gate (<os>)` check name callers already know. With test-shards the
|
||||
# shard legs take its place, and the `result` job reports `gate (<os>)`.
|
||||
name: ${{ matrix.part == 'warm' && 'cache warm' || matrix.part == 'shard' && format('test {0}/{1}', matrix.shard, inputs.test-shards) || 'gate' }} (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: ${{ inputs.timeout-minutes }}
|
||||
strategy:
|
||||
# A failing leg must not cancel the others and hide their failures.
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: ${{ fromJSON(needs.select.outputs.os || inputs.os) }}
|
||||
# One job definition for every part, so the shared setup is written once.
|
||||
part: ${{ fromJSON(format('["{0}"{1}]', inputs.test-shards != 0 && 'shard' || 'test', inputs.warm-command != '' && inputs.archive-command == '' && github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) && ',"warm"' || '')) }}
|
||||
# With test-shards, 1..N for the shard part; the warm leg runs once, as shard 1. Otherwise 0.
|
||||
shard: ${{ fromJSON(needs.select.outputs.shards || '[0]') }}
|
||||
exclude: ${{ fromJSON(needs.select.outputs.exclude || '[]') }}
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_NET_RETRY: 10
|
||||
RUST_BACKTRACE: 1
|
||||
steps:
|
||||
- *harden-runner
|
||||
- *checkout
|
||||
|
||||
# Shard legs restore the test part's entry, and shard 1 alone saves it (the warm leg, when
|
||||
# there is one), so the shards do not race each other for it. Shards that run the build
|
||||
# job's archive build nothing and restore no cache.
|
||||
- name: Setup
|
||||
uses: storytold/craft-common-actions/actions/gate-setup@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
craft-fonts-ref: ${{ inputs.craft-fonts-ref }}
|
||||
require-craft-fonts: ${{ inputs.require-craft-fonts }}
|
||||
env: ${{ inputs.env }}
|
||||
linux-env: ${{ inputs.linux-env }}
|
||||
windows-env: ${{ inputs.windows-env }}
|
||||
dev-debug: ${{ inputs.dev-debug }}
|
||||
dev-strip: ${{ inputs.dev-strip }}
|
||||
free-disk-space: ${{ inputs.free-disk-space }}
|
||||
packages: ${{ inputs.packages }}
|
||||
toolchain: ${{ inputs.toolchain }}
|
||||
targets: ${{ inputs.targets }}
|
||||
tools: ${{ inputs.tools }}
|
||||
rust-cache: ${{ !(matrix.part == 'shard' && inputs.archive-command != '') }}
|
||||
cache-version: ${{ inputs.cache-version }}
|
||||
cache-job: ${{ inputs.cache-name != '' && format('gate-{0}', inputs.cache-name) || 'gate' }}
|
||||
cache-save: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) && (matrix.part == 'warm' || inputs.warm-command == '' && matrix.shard <= 1) }}
|
||||
cache-workspace-crates: ${{ inputs.cache-workspace-crates }}
|
||||
cold-build: ${{ inputs.cold-build }}
|
||||
sccache: ${{ inputs.sccache }}
|
||||
writes: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) }}
|
||||
cache-paths: ${{ inputs.cache-paths }}
|
||||
cache-key: ${{ inputs.cache-key }}
|
||||
cache-key-files: ${{ inputs.cache-key-files }}
|
||||
setup-command: ${{ inputs.setup-command }}
|
||||
|
||||
- name: Download the test archive
|
||||
if: matrix.part == 'shard' && inputs.archive-command != ''
|
||||
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
||||
with:
|
||||
name: gate-archive-${{ matrix.os }}
|
||||
path: ${{ runner.temp }}/gate-archive
|
||||
|
||||
- name: Archive path
|
||||
if: matrix.part == 'shard' && inputs.archive-command != ''
|
||||
shell: bash
|
||||
env:
|
||||
SETUP: ${{ inputs.setup-command }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
printf '%s\n' "$SETUP" > "$RUNNER_TEMP/gate-setup.sh"
|
||||
bash -euo pipefail "$RUNNER_TEMP/gate-setup.sh"
|
||||
|
||||
# Saved where the dependency cache is saved, as soon as the setup has filled it. Every leg
|
||||
# tries; the first to finish writes the entry and the others find it reserved.
|
||||
- name: Save caller cache
|
||||
if: >-
|
||||
inputs.cache-paths != '' && matrix.part != 'lint' && steps.caller-cache.outputs.cache-hit != 'true'
|
||||
&& github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch'))
|
||||
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5
|
||||
with:
|
||||
path: ${{ inputs.cache-paths }}
|
||||
key: ${{ steps.caller-key.outputs.key }}
|
||||
enableCrossOsArchive: true
|
||||
FILE: ${{ runner.temp }}/gate-archive/${{ inputs.archive-file }}
|
||||
run: echo "NEXTEST_ARCHIVE_FILE=$FILE" >> "$GITHUB_ENV"
|
||||
|
||||
# Which share of the tests a shard leg runs.
|
||||
- name: Shard environment
|
||||
@@ -522,47 +584,27 @@ jobs:
|
||||
} >> "$GITHUB_ENV"
|
||||
|
||||
- name: Gate
|
||||
shell: bash
|
||||
env:
|
||||
GATE: >-
|
||||
${{ matrix.part == 'lint' && inputs.lint-command || matrix.part == 'warm' && inputs.warm-command
|
||||
uses: storytold/craft-common-actions/actions/gate-run@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
command: >-
|
||||
${{ matrix.part == 'warm' && inputs.warm-command
|
||||
|| matrix.part == 'shard' && (runner.os == 'Windows' && inputs.windows-shard-command != '' && inputs.windows-shard-command || inputs.shard-command)
|
||||
|| runner.os == 'Windows' && inputs.windows-command != '' && inputs.windows-command || inputs.command }}
|
||||
GATE_TIMEOUT: ${{ inputs.gate-timeout-minutes }}
|
||||
run: |
|
||||
printf '%s\n' "$GATE" > "$RUNNER_TEMP/gate.sh"
|
||||
# gate-timeout-minutes: GNU timeout stops a hung command before the job's own timeout
|
||||
# would, so the log says which processes hung instead of just "cancelled".
|
||||
if [[ ! "$GATE_TIMEOUT" =~ ^[1-9][0-9]*$ ]] || ! timeout --version >/dev/null 2>&1; then
|
||||
[[ "$GATE_TIMEOUT" =~ ^0*$ ]] || echo "::warning title=Gate timeout not set::gate-timeout-minutes '$GATE_TIMEOUT' needs a whole number of minutes and GNU timeout"
|
||||
exec bash -euo pipefail "$RUNNER_TEMP/gate.sh"
|
||||
fi
|
||||
snapshot() {
|
||||
echo "::group::Processes running one minute before the gate timeout"
|
||||
if [ "$RUNNER_OS" = Windows ]; then ps -W; else ps -eo pid,ppid,etime,args; fi || true
|
||||
echo "::endgroup::"
|
||||
}
|
||||
(
|
||||
sleep $(( GATE_TIMEOUT * 60 - 60 )) & sleeper=$!
|
||||
trap 'kill "$sleeper" 2>/dev/null; exit 0' TERM
|
||||
wait "$sleeper" && snapshot
|
||||
) &
|
||||
watchdog=$!
|
||||
status=0
|
||||
timeout --kill-after=30s "${GATE_TIMEOUT}m" bash -euo pipefail "$RUNNER_TEMP/gate.sh" || status=$?
|
||||
kill "$watchdog" 2>/dev/null || true
|
||||
wait "$watchdog" 2>/dev/null || true
|
||||
if [ "$status" -eq 124 ] || [ "$status" -eq 137 ]; then
|
||||
echo "::error title=Gate timed out::the gate command ran for over $GATE_TIMEOUT min and was stopped. The 'Processes running one minute before the gate timeout' group shows what was still running; for cargo test, the 'has been running for over 60 seconds' lines name the hung tests."
|
||||
fi
|
||||
exit "$status"
|
||||
timeout-minutes: ${{ inputs.gate-timeout-minutes }}
|
||||
|
||||
# The marker is saved with the cache entry in rust-cache's post step, where the leg saves.
|
||||
- name: Record the cache commit
|
||||
if: inputs.cache-workspace-crates && !(matrix.part == 'shard' && inputs.archive-command != '')
|
||||
uses: storytold/craft-common-actions/actions/restore-mtimes@d82b20d6b7fdd7bdbf674aef95db3b72a5efb283
|
||||
with:
|
||||
mode: record
|
||||
|
||||
# A gate that changed Cargo.lock ran against a lockfile that is not the one in the repository.
|
||||
- name: Lockfile unchanged
|
||||
shell: bash
|
||||
run: git diff --exit-code -- Cargo.lock
|
||||
|
||||
# Only the unsharded test/build producer uploads: lint/warm/shard parts must not race it.
|
||||
# Only the unsharded test/build producer uploads: warm/shard parts must not race it.
|
||||
- name: Upload artifact
|
||||
if: inputs.artifact-name != '' && matrix.part == 'test'
|
||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
@@ -580,25 +622,26 @@ jobs:
|
||||
if: always() && matrix.part == 'shard'
|
||||
shell: bash
|
||||
env:
|
||||
RESULT: ${{ runner.temp }}/gate-shard
|
||||
RESULT: ${{ runner.temp }}/gate-result/gate-shard-${{ matrix.os }}-${{ matrix.shard }}
|
||||
STATUS: ${{ job.status }}
|
||||
run: mkdir -p "$RESULT" && echo "$STATUS" > "$RESULT/status"
|
||||
run: mkdir -p "$(dirname "$RESULT")" && echo "$STATUS" > "$RESULT"
|
||||
|
||||
- name: Upload the leg's result
|
||||
if: always() && matrix.part == 'shard'
|
||||
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
with:
|
||||
name: gate-shard-${{ matrix.os }}-${{ matrix.shard }}
|
||||
path: ${{ runner.temp }}/gate-shard/status
|
||||
path: ${{ runner.temp }}/gate-result/gate-shard-${{ matrix.os }}-${{ matrix.shard }}
|
||||
if-no-files-found: error
|
||||
overwrite: true
|
||||
retention-days: 1
|
||||
|
||||
# With test-shards, the gate's result per runner under the `gate (<os>)` name the unsharded leg
|
||||
# has, so required checks stay as they are: it passes only when every one of that runner's shards
|
||||
# passed. It waits for every gate leg, since a matrix job's `needs` cannot pick one runner's legs.
|
||||
# passed, and with archive-command its build job too. It waits for every gate leg, since a matrix
|
||||
# job's `needs` cannot pick one runner's legs.
|
||||
result:
|
||||
needs: [select, gate]
|
||||
needs: [select, build, gate]
|
||||
if: ${{ !cancelled() && inputs.test-shards != 0 }}
|
||||
name: gate (${{ matrix.os }})
|
||||
runs-on: ubuntu-24.04
|
||||
@@ -612,23 +655,37 @@ jobs:
|
||||
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
|
||||
with:
|
||||
egress-policy: audit
|
||||
# Each marker lands in a directory named after it; a runner with no recorded leg downloads none.
|
||||
- name: Download the legs' results
|
||||
# Each marker is a file named after its leg, so the markers merge into one directory however
|
||||
# many there are; a runner with no recorded leg downloads none.
|
||||
- name: Download the shards' results
|
||||
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
||||
with:
|
||||
pattern: gate-shard-${{ matrix.os }}-*
|
||||
path: ${{ runner.temp }}/gate-shard
|
||||
path: ${{ runner.temp }}/gate-result
|
||||
merge-multiple: true
|
||||
- name: Download the build's result
|
||||
if: inputs.archive-command != ''
|
||||
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
||||
with:
|
||||
pattern: gate-build-${{ matrix.os }}
|
||||
path: ${{ runner.temp }}/gate-result
|
||||
merge-multiple: true
|
||||
- name: Every leg passed
|
||||
shell: bash
|
||||
env:
|
||||
RESULT: ${{ runner.temp }}/gate-shard
|
||||
RESULT: ${{ runner.temp }}/gate-result
|
||||
OS: ${{ matrix.os }}
|
||||
SHARDS: ${{ inputs.test-shards }}
|
||||
BUILD: ${{ inputs.archive-command != '' }}
|
||||
run: |
|
||||
set -uo pipefail
|
||||
status=0
|
||||
if [ "${BUILD:-false}" = true ] && [ "$(cat "$RESULT/gate-build-$OS" 2>/dev/null)" != success ]; then
|
||||
echo "::error::build ($OS) did not pass"
|
||||
status=1
|
||||
fi
|
||||
for shard in $(seq 1 "$SHARDS"); do
|
||||
if [ "$(cat "$RESULT/gate-shard-$OS-$shard/status" 2>/dev/null)" != success ]; then
|
||||
if [ "$(cat "$RESULT/gate-shard-$OS-$shard" 2>/dev/null)" != success ]; then
|
||||
echo "::error::test $shard/$SHARDS ($OS) did not pass"
|
||||
status=1
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user