Files
craft-common-actions/.github/workflows/gate.yml
T
aiongg 6b0c83fa60 gate: cache-name and dev-strip inputs; manual Windows build diagnostic
cache-name gives each call of the gate in one job its own dependency-cache entry (gate-<name>); the default keeps today's key. dev-strip builds the test profile without debug info and strips symbols.
2026-11-19 02:21:58 +00:00

637 lines
30 KiB
YAML

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.
# 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:
workflow_call:
inputs:
packages:
description: "Ubuntu packages the build needs, separated by spaces or newlines; installed on Linux legs through the cached install-apt-packages action. Empty installs none (Windows-only calls, wasm builds)"
type: string
required: false
default: ""
command:
description: "The gate, run with bash from the repository root"
type: string
required: false
default: "cargo xtask ci"
artifact-name:
description: "Optional unsharded test/build output, uploaded as <artifact-name>-<matrix.os>; empty uploads nothing"
type: string
required: false
default: ""
artifact-path:
description: "Files or patterns to upload after the gate and lockfile checks; fails if no files match"
type: string
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"
type: string
required: false
default: ""
setup-command:
description: "Optional setup script, run from the repository root before the gate (for example, fetch SHA-verified corpora)"
type: string
required: false
default: ""
cache-paths:
description: "Paths (one per line) that setup-command fills, restored before it and saved after it where the dependency cache saves; empty caches none. One entry serves every OS"
type: string
required: false
default: ""
cache-key:
description: "The key for cache-paths; put the pins of what setup-command fetches in it, so a new pin starts a new entry"
type: string
required: false
default: ""
cache-key-files:
description: "A glob of files (the fetch script that holds the pins, say) whose hash is added to cache-key; empty adds none"
type: string
required: false
default: ""
windows-command:
description: "The gate on Windows legs; empty runs `command`"
type: string
required: false
default: ""
lint-command:
description: "Lint checks (fmt, clippy) run with bash on a `lint (<os>)` leg beside each `gate (<os>)` leg, so they stay off the test leg's critical path; the lint leg skips setup-command and the caller cache. Empty runs no lint legs"
type: string
required: false
default: ""
test-shards:
description: "0 (default): one `gate (<os>)` leg per runner runs `command`. N > 0: per runner, N `test <k>/<N> (<os>)` legs each run `shard-command`, and `gate (<os>)` passes only when all of them did"
type: number
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\"`"
type: string
required: false
default: ""
windows-shard-command:
description: "shard-command on Windows legs; empty runs `shard-command`"
type: string
required: false
default: ""
os:
description: 'JSON array of runner labels; one leg per entry, e.g. ["ubuntu-24.04","windows-latest"]'
type: string
required: false
default: '["ubuntu-24.04"]'
select-os:
description: 'JSON array of the `os` entries that run on a pull request only when it can change platform behaviour (actions/select-platforms: platform cfg code or its dependents, the build setup, select-paths); pushes and other events run every leg. Empty or [] runs every leg on every event'
type: string
required: false
default: "[]"
select-paths:
description: "Extra globs, one per line, whose change runs the select-os legs (`*` also matches `/`)"
type: string
required: false
default: ""
select-crates:
description: "Extra workspace crates, one per line, treated as having platform code"
type: string
required: false
default: ""
select-label:
description: "A pull request label that runs every leg, read when the run starts; empty: none"
type: string
required: false
default: "full-ci"
craft-fonts-ref:
# The suite's craft-fonts pin, as in release.yml and freebsd.yml.
description: "The commit of storytold/craft-fonts the tests build with. Defaults to the suite's pin; empty builds without craft-fonts"
type: string
required: false
default: "bfcbf714e45a3ea8e98f88ab2b7971372a576414"
require-craft-fonts:
description: "Set CRAFT_FONTS_REQUIRED=1 when craft-fonts is checked out, so a build that silently drops its fonts fails here as it would in a release"
type: boolean
required: false
default: true
toolchain:
description: "rustup toolchain to install when rust-toolchain.toml names no channel"
type: string
required: false
default: "stable"
targets:
description: "Extra rustup targets, separated by spaces or commas"
type: string
required: false
default: "wasm32-unknown-unknown"
tools:
description: "Prebuilt cargo tools from taiki-e/install-action, comma-separated, each with its version (e.g. cargo-nextest@0.9.150,cargo-deny@0.20.2); empty installs none"
type: string
required: false
default: "cargo-nextest@0.9.150"
env:
description: "KEY=VALUE lines added to the environment of every leg before the cache is restored"
type: string
required: false
default: ""
linux-env:
description: "KEY=VALUE lines for Linux legs only"
type: string
required: false
default: ""
windows-env:
description: "KEY=VALUE lines for Windows legs only"
type: string
required: false
default: ""
dev-debug:
description: "CARGO_PROFILE_DEV_DEBUG for the gate (the test profile inherits it); empty leaves the repository's profile alone"
type: string
required: false
default: "line-tables-only"
dev-strip:
description: "Build the test profile with no debug info and strip symbols (CARGO_PROFILE_TEST_DEBUG=0, CARGO_PROFILE_TEST_STRIP=symbols): test binaries shrink to about a third and panics keep their file:line, while backtraces lose function names. Local builds are unaffected"
type: boolean
required: false
default: false
cache-name:
description: "Names this call's dependency-cache entry (`gate-<name>`), so several calls of this workflow in one job do not share one key and overwrite each other's entry; empty keeps the `gate` entry"
type: string
required: false
default: ""
free-disk-space:
description: "Delete the Linux image's unused toolchains (Android, .NET, GHC, CodeQL) in the background before the build"
type: boolean
required: false
default: true
sccache:
description: "Also cache the workspace crates' compiled libraries (which rust-cache leaves out) with sccache in the GitHub Actions cache. It writes where the dependency cache is saved (pushes to the default branch, opted-in manual runs); other runs read those entries. SCCACHE_GHA_RW_MODE in `env` overrides that. Test executables are never cached. Its cache starts afresh when cache-version, a Cargo.toml or a build.rs changes; bump cache-version when files a procedural macro reads change (see the README)"
type: boolean
required: false
default: false
cache-version:
description: "Bump to start the dependency cache afresh"
type: string
required: false
# Same default as actions/rust-cache, which explains the v2 bump.
default: "v2"
cache-save-on-dispatch:
description: "Allow manually dispatched branch runs to save their branch-scoped dependency cache; pull requests never write"
type: boolean
required: false
default: false
timeout-minutes:
description: "Timeout of each leg"
type: number
required: false
default: 60
gate-timeout-minutes:
description: "Stop the gate command after this many minutes, a few before the leg's timeout-minutes, and report it as timed out with the processes still running a minute before; 0 (default) sets no limit of its own"
type: number
required: false
default: 0
permissions:
contents: read
jobs:
# Runs only with select-os or test-shards; otherwise it is skipped and the gate runs every leg
# in `os`.
select:
name: select legs
if: (inputs.select-os != '' && inputs.select-os != '[]') || inputs.test-shards != 0
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
os: ${{ steps.select.outputs.os }}
shards: ${{ steps.shards.outputs.shards }}
exclude: ${{ steps.shards.outputs.exclude }}
steps:
- name: Harden runner
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
# The merge commit and its first parent. Other events run every leg without a checkout.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
if: github.event_name == 'pull_request' && inputs.select-os != '' && inputs.select-os != '[]'
with:
persist-credentials: false
fetch-depth: 2
- id: select
if: inputs.select-os != '' && inputs.select-os != '[]'
uses: storytold/craft-common-actions/actions/select-platforms@main
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.
- name: Shards
id: shards
if: inputs.test-shards != 0
shell: bash
env:
SHARDS: ${{ inputs.test-shards }}
SHARD: ${{ inputs.shard-command }}
run: |
set -euo pipefail
if [[ ! "$SHARDS" =~ ^[1-9][0-9]*$ ]]; then
echo "::error::test-shards must be 0 or a positive whole number, got '$SHARDS'"
exit 1
fi
if [ -z "$SHARD" ]; then
echo "::error::test-shards needs shard-command"
exit 1
fi
exclude=
for shard in $(seq 2 "$SHARDS"); do
exclude+="${exclude:+,}{\"part\":\"lint\",\"shard\":$shard},{\"part\":\"warm\",\"shard\":$shard}"
done
echo "shards=[$(seq -s, 1 "$SHARDS")]" >> "$GITHUB_OUTPUT"
echo "exclude=[$exclude]" >> "$GITHUB_OUTPUT"
gate:
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 }})
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
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
allowed-endpoints: >
*.amazontrust.com:80
*.blob.core.windows.net:443
esm.ubuntu.com:443
motd.ubuntu.com:443
*.crates.io:443
*.github.com:443
*.githubusercontent.com:443
*.microsoft.com:443
*.rust-lang.org:443
*.ubuntu.com:80
*.ubuntu.com:443
api.github.com:443
archive.ubuntu.com:80
archive.ubuntu.com:443
azure.archive.ubuntu.com:80
azure.archive.ubuntu.com:443
crates.io:443
ftp.tu-chemnitz.de:443
github.com:443
index.crates.io:443
*.dotsrc.org:443
*.kernel.org:443
mirrors.dotsrc.org:443
mirrors.edge.kernel.org:443
objects.githubusercontent.com:443
packages.microsoft.com:443
release-assets.githubusercontent.com:443
security.ubuntu.com:80
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 != ''
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@main
# 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@main
with:
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@main
with:
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"
# 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
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
# 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'
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"
- name: Restore caller cache
id: caller-cache
if: inputs.cache-paths != '' && matrix.part != 'lint'
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5
with:
path: ${{ inputs.cache-paths }}
key: ${{ steps.caller-key.outputs.key }}
enableCrossOsArchive: true
- name: Caller setup
if: inputs.setup-command != '' && matrix.part != 'lint'
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
# Which share of the tests a shard leg runs.
- name: Shard environment
if: matrix.part == 'shard'
shell: bash
env:
SHARD: ${{ matrix.shard }}
SHARDS: ${{ inputs.test-shards }}
run: |
{
echo "GATE_SHARD=$SHARD"
echo "GATE_SHARDS=$SHARDS"
echo "NEXTEST_PARTITION=hash:$SHARD/$SHARDS"
} >> "$GITHUB_ENV"
- name: Gate
shell: bash
env:
GATE: >-
${{ matrix.part == 'lint' && inputs.lint-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"
# 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.
- name: Upload artifact
if: inputs.artifact-name != '' && matrix.part == 'test'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ${{ inputs.artifact-name }}-${{ matrix.os }}
path: ${{ inputs.artifact-path }}
if-no-files-found: error
retention-days: 1
# The `result` job reads these, one per shard leg: a matrix job's result covers every runner,
# so it cannot say which runner's shards passed. Each leg's marker holds that leg's latest
# status and lasts for the run: after a re-run of the failed legs the shards that passed before
# still count, and a shard that fails in a later attempt replaces its earlier pass.
- name: Record the leg's result
if: always() && matrix.part == 'shard'
shell: bash
env:
RESULT: ${{ runner.temp }}/gate-shard
STATUS: ${{ job.status }}
run: mkdir -p "$RESULT" && echo "$STATUS" > "$RESULT/status"
- 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
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.
result:
needs: [select, gate]
if: ${{ !cancelled() && inputs.test-shards != 0 }}
name: gate (${{ matrix.os }})
runs-on: ubuntu-24.04
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(needs.select.outputs.os || inputs.os) }}
steps:
- name: Harden runner
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
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: gate-shard-${{ matrix.os }}-*
path: ${{ runner.temp }}/gate-shard
- name: Every leg passed
shell: bash
env:
RESULT: ${{ runner.temp }}/gate-shard
OS: ${{ matrix.os }}
SHARDS: ${{ inputs.test-shards }}
run: |
set -uo pipefail
status=0
for shard in $(seq 1 "$SHARDS"); do
if [ "$(cat "$RESULT/gate-shard-$OS-$shard/status" 2>/dev/null)" != success ]; then
echo "::error::test $shard/$SHARDS ($OS) did not pass"
status=1
fi
done
exit "$status"