mirror of
https://github.com/storytold/craft-common-actions.git
synced 2026-11-19 09:01:25 +01:00
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.
This commit is contained in:
1 parent
7d4597abb2
commit
6b0c83fa60
4 files changed
+146
-8
No files matched your search
@@ -150,6 +150,16 @@ on:
|
||||
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
|
||||
@@ -333,13 +343,14 @@ jobs:
|
||||
|
||||
# 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 != ''
|
||||
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
|
||||
@@ -348,6 +359,10 @@ jobs:
|
||||
*) 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
|
||||
@@ -408,7 +423,7 @@ jobs:
|
||||
- uses: storytold/craft-common-actions/actions/rust-cache@main
|
||||
with:
|
||||
cache-version: ${{ inputs.cache-version }}
|
||||
job: ${{ matrix.part == 'lint' && 'lint' || '' }}
|
||||
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"
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
name: "Windows build diagnostic"
|
||||
|
||||
# Finds why Windows builds take about 1.5x as long as Linux. Run by hand only: it compiles one
|
||||
# repository four ways on the same commit and prints what each variant changes. Nothing calls it.
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
repository:
|
||||
description: "Repository whose tests are compiled"
|
||||
type: string
|
||||
default: "storytold/craft-libs"
|
||||
ref:
|
||||
description: "Branch, tag or commit to compile"
|
||||
type: string
|
||||
default: "main"
|
||||
command:
|
||||
description: "The build to time, run with bash; --timings is added so each unit's duration is kept"
|
||||
type: string
|
||||
default: "cargo test --workspace --no-run --lib --bins --tests --all-features --timings"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
diagnose:
|
||||
name: ${{ matrix.variant }}
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 120
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
variant: [baseline, defender-exclusions, dev-drive, both]
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_PROFILE_DEV_DEBUG: "0"
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
repository: ${{ inputs.repository }}
|
||||
ref: ${{ inputs.ref }}
|
||||
persist-credentials: false
|
||||
|
||||
- name: Machine state
|
||||
shell: pwsh
|
||||
run: |
|
||||
Get-ComputerInfo -Property OsName, OsVersion, CsProcessors | Format-List
|
||||
Get-MpComputerStatus | Select-Object AMRunningMode, RealTimeProtectionEnabled, AntivirusSignatureVersion | Format-List
|
||||
Get-MpPreference | Select-Object DisableRealtimeMonitoring, ExclusionPath, ExclusionProcess | Format-List
|
||||
fsutil fsinfo volumeinfo D:
|
||||
|
||||
# Process start-up cost: rustc is launched once per unit, so a 1.5x ratio here against a Linux
|
||||
# run of the same loop means the gap is per-process cost and only fewer processes help.
|
||||
- name: Launch benchmark
|
||||
shell: pwsh
|
||||
run: |
|
||||
$t = Measure-Command { 1..300 | ForEach-Object { rustc --version | Out-Null } }
|
||||
"300 launches of rustc --version: $($t.TotalSeconds) s"
|
||||
|
||||
- name: Defender exclusions
|
||||
if: matrix.variant == 'defender-exclusions' || matrix.variant == 'both'
|
||||
shell: pwsh
|
||||
run: |
|
||||
Add-MpPreference -ExclusionPath 'D:\t', "$env:USERPROFILE\.cargo", "$env:USERPROFILE\.rustup", "$env:GITHUB_WORKSPACE"
|
||||
Add-MpPreference -ExclusionProcess 'rustc.exe', 'cargo.exe', 'link.exe', 'rust-lld.exe'
|
||||
Get-MpPreference | Select-Object ExclusionPath, ExclusionProcess | Format-List
|
||||
|
||||
# A ReFS Dev Drive for the target directory; Defender runs it in performance mode.
|
||||
- name: Dev Drive
|
||||
if: matrix.variant == 'dev-drive' || matrix.variant == 'both'
|
||||
shell: pwsh
|
||||
run: |
|
||||
$vhd = New-VHD -Path 'D:\devdrive.vhdx' -SizeBytes 30GB -Dynamic
|
||||
$disk = Mount-VHD -Path $vhd.Path -Passthru | Initialize-Disk -PassThru
|
||||
$volume = New-Partition -InputObject $disk -AssignDriveLetter -UseMaximumSize | Format-Volume -DevDrive -Confirm:$false -Force
|
||||
"CARGO_TARGET_DIR=$($volume.DriveLetter):\t" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
|
||||
fsutil devdrv query "$($volume.DriveLetter):"
|
||||
|
||||
- name: Target directory
|
||||
if: matrix.variant == 'baseline' || matrix.variant == 'defender-exclusions'
|
||||
shell: pwsh
|
||||
run: '"CARGO_TARGET_DIR=D:\t" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8'
|
||||
|
||||
- name: Install Rust
|
||||
shell: bash
|
||||
run: |
|
||||
if [ -f rust-toolchain.toml ]; then channel=$(sed -n 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' rust-toolchain.toml); fi
|
||||
rustup toolchain install "${channel:-stable}" --profile minimal --no-self-update
|
||||
rustup default "${channel:-stable}"
|
||||
rustc --version
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
env:
|
||||
BUILD: ${{ inputs.command }}
|
||||
run: |
|
||||
start=$(date +%s)
|
||||
bash -euo pipefail -c "$BUILD"
|
||||
echo "build seconds: $(( $(date +%s) - start ))"
|
||||
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
if: always()
|
||||
with:
|
||||
name: timings-${{ matrix.variant }}
|
||||
path: ${{ env.CARGO_TARGET_DIR }}/cargo-timings/*.html
|
||||
if-no-files-found: warn
|
||||
@@ -528,8 +528,10 @@ The quality gate for an app's pull requests and pushes to main. It runs `command
|
||||
- the channel from `rust-toolchain.toml`, or `toolchain`, with clippy, rustfmt and `targets`;
|
||||
- prebuilt cargo tools from `tools` (by default `cargo-nextest@0.9.150`);
|
||||
- `CARGO_PROFILE_DEV_DEBUG=line-tables-only` (set `dev-debug: ""` to keep the repository's
|
||||
profile) and the caller's `env`, `linux-env` and `windows-env` lines, each `KEY=VALUE`;
|
||||
- a rust-cache dependency cache saved by the default branch by default. Pull requests only
|
||||
profile), `dev-strip: true` (no debug info and stripped symbols in the test profile, for CI test
|
||||
builds; off by default) and the caller's `env`, `linux-env` and `windows-env` lines, each `KEY=VALUE`;
|
||||
- a rust-cache dependency cache saved by the default branch by default; give each call of the
|
||||
workflow in one job a `cache-name` (`gate-<name>` entry) so the calls do not share one key; Pull requests only
|
||||
restore caches; callers may opt manual branch runs into branch-scoped writes with
|
||||
`cache-save-on-dispatch: true`. The restore prefix includes the canonical root `[profile]`
|
||||
table without the wasm-only profiles (names `web` or `wasm`, with or without a `-suffix`);
|
||||
|
||||
+19
-4
@@ -382,7 +382,7 @@ class CallerEnvironmentTests(unittest.TestCase):
|
||||
STEP = step('Caller environment')
|
||||
|
||||
def run_step(self, runner_os='Linux', **inputs):
|
||||
env = {'ALL': '', 'LINUX': '', 'WINDOWS': '', 'DEV_DEBUG': '', **inputs}
|
||||
env = {'ALL': '', 'LINUX': '', 'WINDOWS': '', 'DEV_DEBUG': '', 'DEV_STRIP': 'false', **inputs}
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
github_env = Path(directory, 'github_env')
|
||||
github_env.touch()
|
||||
@@ -393,7 +393,7 @@ class CallerEnvironmentTests(unittest.TestCase):
|
||||
return result.returncode, github_env.read_text().splitlines()
|
||||
|
||||
def test_the_step_reads_its_inputs_from_env(self):
|
||||
self.assertEqual(set(self.STEP['env']), {'ALL', 'LINUX', 'WINDOWS', 'DEV_DEBUG'})
|
||||
self.assertEqual(set(self.STEP['env']), {'ALL', 'LINUX', 'WINDOWS', 'DEV_DEBUG', 'DEV_STRIP'})
|
||||
|
||||
def test_writes_shared_and_per_os_lines(self):
|
||||
inputs = {'ALL': 'A=1\n\nB=two words', 'LINUX': 'ONLY_LINUX=1', 'WINDOWS': 'ONLY_WINDOWS=1',
|
||||
@@ -402,6 +402,10 @@ class CallerEnvironmentTests(unittest.TestCase):
|
||||
'CARGO_PROFILE_DEV_DEBUG=line-tables-only', 'A=1', 'B=two words', 'ONLY_LINUX=1']))
|
||||
self.assertEqual(self.run_step('Windows', **inputs)[1][-1], 'ONLY_WINDOWS=1')
|
||||
|
||||
def test_dev_strip_sets_the_test_profile(self):
|
||||
self.assertEqual(self.run_step(DEV_STRIP='true')[1],
|
||||
['CARGO_PROFILE_TEST_DEBUG=0', 'CARGO_PROFILE_TEST_STRIP=symbols'])
|
||||
|
||||
def test_rejects_a_line_that_is_not_key_value(self):
|
||||
for line in ('NOT AN ASSIGNMENT', '1X=1', 'X<<EOF'):
|
||||
with self.subTest(line=line):
|
||||
@@ -490,7 +494,7 @@ class WarmPartTests(unittest.TestCase):
|
||||
self.assertTrue(step('Gate')['env']['GATE'].startswith(
|
||||
"${{ matrix.part == 'lint' && inputs.lint-command || matrix.part == 'warm' && inputs.warm-command || "))
|
||||
cache = next(s for s in STEPS if 'rust-cache' in s.get('uses', ''))['with']
|
||||
self.assertEqual(cache['job'], "${{ matrix.part == 'lint' && 'lint' || '' }}")
|
||||
self.assertEqual(cache['job'], "${{ matrix.part == 'lint' && 'lint' || inputs.cache-name != '' && format('gate-{0}', inputs.cache-name) || '' }}")
|
||||
self.assertIn("matrix.part == 'lint' || matrix.part == 'warm' || inputs.warm-command == '' && matrix.shard <= 1", cache['save-if'])
|
||||
self.assertEqual(cache['cache-on-failure'], 'false')
|
||||
|
||||
@@ -516,9 +520,20 @@ class LintPartTests(unittest.TestCase):
|
||||
self.assertTrue(gate.startswith("${{ matrix.part == 'lint' && inputs.lint-command || "), gate)
|
||||
self.assertIn("matrix.part != 'lint'", step('Caller setup')['if'])
|
||||
|
||||
def test_cache_name_gives_each_call_its_own_entry(self):
|
||||
cache = next(s for s in STEPS if 'rust-cache' in s.get('uses', ''))
|
||||
self.assertIn("inputs.cache-name != '' && format('gate-{0}', inputs.cache-name)", cache['with']['job'])
|
||||
self.assertEqual(WORKFLOW['on']['workflow_call']['inputs']['cache-name']['default'], '')
|
||||
|
||||
def test_dev_strip_is_off_by_default_and_sets_the_test_profile(self):
|
||||
self.assertEqual(str(WORKFLOW['on']['workflow_call']['inputs']['dev-strip']['default']).lower(), 'false')
|
||||
run = step('Caller environment')['run']
|
||||
self.assertIn('CARGO_PROFILE_TEST_STRIP=symbols', run)
|
||||
self.assertIn('CARGO_PROFILE_TEST_DEBUG=0', run)
|
||||
|
||||
def test_lint_keeps_a_cache_entry_of_its_own(self):
|
||||
cache = next(s for s in STEPS if 'rust-cache' in s.get('uses', ''))
|
||||
self.assertEqual(cache['with']['job'], "${{ matrix.part == 'lint' && 'lint' || '' }}")
|
||||
self.assertEqual(cache['with']['job'], "${{ matrix.part == 'lint' && 'lint' || inputs.cache-name != '' && format('gate-{0}', inputs.cache-name) || '' }}")
|
||||
|
||||
|
||||
SHARDED = dict(test_shards=3, shard_command='cargo nextest run --workspace --partition "$NEXTEST_PARTITION"')
|
||||
|
||||
Reference in new issue
Block a user