-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaction.yml
More file actions
185 lines (176 loc) · 8.72 KB
/
Copy pathaction.yml
File metadata and controls
185 lines (176 loc) · 8.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# GENERATED BY cargo-anvil. DO NOT EDIT DIRECTLY.
# Update cargo-anvil and regenerate; repository-specific edits stop automatic updates.
# Update behaviour: https://github.com/microsoft/ox-tools/blob/main/crates/cargo-anvil/docs/design/updates.md
name: anvil-setup
description: Install `just` and the anvil tools/components needed by a specific group (or everything if omitted).
inputs:
group:
description: |
Which anvil group to install setup for (e.g. "pr-fast",
"pr-test", "scheduled-advisories"). Special values:
- "" (default): install the full catalog via
`just anvil-setup` -- use for local "give me everything"
flows.
- "none": skip tool installation entirely; just restore the
Cargo cache and bootstrap just + binstall. Used by
anvil-impact, which installs only cargo-delta afterwards.
- a name containing only lowercase letters, digits, and hyphens:
install only that group's prerequisites via
`just anvil-<group>-setup`.
default: ""
required: false
free-disk-space:
description: >-
Remove unused pre-installed toolchains from GitHub-hosted Linux and
Windows runners before setup. Reclaims approximately 18 GB on Linux and
17 GB on Windows. No-op on macOS and self-hosted runners.
default: "false"
required: false
runs:
using: composite
steps:
# Just reports the exact failing dependency recipe on stderr. GitHub
# otherwise reduces that to "Process completed with exit code 1", so
# promote Just's diagnostic to a workflow annotation.
- name: Register Just problem matcher
shell: bash
run: echo "::add-matcher::$GITHUB_ACTION_PATH/just-problem-matcher.json"
# Standard GitHub-hosted runners guarantee only 14 GB of SSD space. Heavy
# build and test jobs can exceed that with target artifacts alone, so this
# opt-in cleanup removes toolchains unused by anvil's Rust checks.
# See https://github.com/microsoft/oxidizer/pull/583.
- name: Free disk space (Linux)
if: inputs.free-disk-space == 'true' && runner.environment == 'github-hosted' && runner.os == 'Linux'
shell: bash
run: |
echo "Disk before cleanup:"
df -h /
# Android ~10 GB, Haskell ~4 GB, Swift ~3 GB, browser drivers ~1 GB.
sudo rm -rf -- /usr/local/lib/android
sudo rm -rf -- /opt/ghc /usr/local/.ghcup
sudo rm -rf -- /usr/share/swift
sudo rm -rf -- /usr/local/share/chromium /usr/local/share/edge_driver
echo "Disk after cleanup:"
df -h /
- name: Free disk space (Windows)
if: inputs.free-disk-space == 'true' && runner.environment == 'github-hosted' && runner.os == 'Windows'
shell: pwsh -NoProfile -Command ". '{0}'"
run: |
function Get-FreeDiskGiB {
[math]::Round((Get-CimInstance Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace / 1GB, 1)
}
"Free before cleanup (GiB): $(Get-FreeDiskGiB)"
$paths = @(
'C:\Program Files (x86)\Android'
'C:\Android'
'C:\ghcup'
)
foreach ($path in $paths) {
if (Test-Path -LiteralPath $path) {
Remove-Item -LiteralPath $path -Recurse -Force
}
}
"Free after cleanup (GiB): $(Get-FreeDiskGiB)"
# Restore before bootstrapping Just so a warm job can reuse the cached
# executable. Repository toolchain files intentionally define a fresh
# cache generation, bounding registry growth without invalidating on
# routine Cargo.toml or Cargo.lock edits.
- name: Restore cargo cache
id: cargo-cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
# The job suffix prevents concurrent matrix jobs from racing to save
# one key. The prefix shares a completed cache across sibling jobs.
# There is deliberately no fallback across toolchain/catalog changes:
# those inputs are the cache-pruning boundary.
key: anvil-v2-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.cargo/config.toml', 'rust-toolchain', 'rust-toolchain.toml', 'justfiles/anvil/versions.just') }}-${{ github.job }}
restore-keys: |
anvil-v2-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.cargo/config.toml', 'rust-toolchain', 'rust-toolchain.toml', 'justfiles/anvil/versions.just') }}-
# `.crates.toml` and `.crates2.json` track which cargo-installed
# tools and versions live in ~/.cargo/bin/. Without them in the
# cache, `cargo install --list` and (downstream) the
# tool-install recipes' early-skip on "installed >= pin" don't
# see the cached binaries.
#
# target/ is deliberately excluded: per-job target trees dwarf the
# tool cache and could overwrite the downloaded impact cache.
path: |
~/.cargo/registry/cache/
~/.cargo/registry/index/
~/.cargo/bin/
~/.cargo/.crates.toml
~/.cargo/.crates2.json
# cargo-binstall keeps the cold bootstrap path fast.
- name: Install cargo-binstall
uses: cargo-bins/cargo-binstall@v1.21.0 # immutable release, the tag cannot be moved
- name: Install just
shell: bash
run: |
if ! command -v just >/dev/null 2>&1 ; then
cargo binstall --no-confirm --locked just || cargo install --locked just
fi
# The catalog recipe `anvil-setup` (or `anvil-<group>-setup`
# when a group is specified via the `group` input) uses the Just executable
# bootstrapped above, then handles everything else. The setup recipes are idempotent and
# short-circuit on tools already installed at or above the pinned
# version, so re-running on cache-hit runs is cheap.
- name: Install anvil toolchains + tools
shell: bash
# Carry action data through the environment instead of interpolating it
# into shell source. Validation below occurs before path or recipe-name
# composition.
env:
ANVIL_GROUP: ${{ inputs.group }}
# When `group` is empty (the default), installs the full catalog
# via `just anvil-setup binstall`. When `group` is "none",
# skips tool installation entirely (used by anvil-impact, which
# only needs cargo-delta and installs it itself afterwards). When
# `group` is anything else, installs only what that group needs
# via `just anvil-<group>-setup binstall`.
#
# binstall path downloads prebuilt tool binaries from each tool's
# GitHub Releases when available (~1 min cold, vs ~30 min for
# source builds). cargo-binstall has unresolved compliance issues
# for ADO pipelines, so the ADO backend uses the default `install`
# path; GH uses `binstall`.
run: |
if [[ -n "$ANVIL_GROUP" && "$ANVIL_GROUP" != "none" && ! "$ANVIL_GROUP" =~ ^[a-z0-9-]+$ ]]; then
echo "::error::Invalid Anvil group; expected lowercase letters, digits, and hyphens."
# Distinguish invalid action input from a setup-recipe failure.
exit 2
fi
case "$ANVIL_GROUP" in
none) echo "anvil-setup: group=none, skipping tool install" ;;
"") just anvil-setup binstall ;;
*) just "anvil-$ANVIL_GROUP-setup" binstall ;;
esac
# Save the cache as the LAST step of setup, regardless of whether
# any earlier install step partially failed. `actions/cache`
# used to support this via `save-always: true`, but that knob is
# deprecated as of 2025 with the explicit message "does not work
# as intended" — failing runs simply don't save. The supported
# replacement is to call `actions/cache/save` directly as its
# own step with `if: always()`.
#
# Without this, a single catalog issue that fails the install
# step locks the cache empty forever (chicken-and-egg: failed
# run -> no save -> next run cold-starts -> still fails -> still
# no save). Tool binaries installed by anvil-tools-install are
# immutable once on disk, so partial state is strictly better
# than nothing — and subsequent runs accumulate into the cache
# until the catalog is complete.
- name: Save cargo cache
if: always() && steps.cargo-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
key: ${{ steps.cargo-cache.outputs.cache-primary-key }}
# target/ deliberately excluded from the save path too -- see the
# restore step above for why (cache-quota / impact-cache-clobber).
path: |
~/.cargo/registry/cache/
~/.cargo/registry/index/
~/.cargo/bin/
~/.cargo/.crates.toml
~/.cargo/.crates2.json