Skip to content

Commit a5c3f3e

Browse files
ci: cache each job (#2025)
1 parent b491987 commit a5c3f3e

1 file changed

Lines changed: 34 additions & 95 deletions

File tree

.github/workflows/ci.yml

Lines changed: 34 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Continuous integration jobs.
22
#
3-
# These get run on every pull-request.
3+
# These get run on every pull-request, with Warp caches updated on push into `main` or `next`.
44
name: CI
55

66
permissions:
@@ -23,33 +23,12 @@ on:
2323
- "docs/**"
2424

2525
env:
26-
# Shared prefix key for the rust cache.
26+
# Shared prefix key for the Rust caches.
2727
#
28-
# This provides a convenient way to evict old or corrupted cache.
29-
RUST_CACHE_PREFIX: rust-cache
30-
# Shared branch-aware cache namespace for rust-cache.
31-
#
32-
# Pushes save to the persistent trunk cache, while pull requests append the
33-
# PR number so they save into an ephemeral PR-specific cache.
34-
#
35-
# The format is <main | next> with an optional `-pr-<PR>` for pull requests.
36-
# We default to next if no suitable is found.
37-
RUST_CACHE_SUFFIX: >-
38-
${{
39-
format(
40-
'{0}{1}',
41-
github.base_ref == 'main' && 'main'
42-
|| github.base_ref == 'next' && 'next'
43-
|| github.ref == 'refs/heads/main' && 'main'
44-
|| github.ref == 'refs/heads/next' && 'next'
45-
|| 'next',
46-
github.event_name == 'pull_request'
47-
&& format('-pr-{0}', github.event.pull_request.number)
48-
|| ''
49-
)
50-
}}
51-
# Match rust-cache's compilation mode so restored outputs stay reusable downstream.
52-
CARGO_INCREMENTAL: 0
28+
# Cache is trunk specific (next|main).
29+
CACHE_PREFIX: rust-cache-${{ github.base_ref || github.ref_name }}
30+
# Only trusted branch pushes should update caches; PRs restore from the target branch cache.
31+
SAVE_CACHE: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/next') }}
5332
# Reduce cache usage by removing debug information.
5433
CARGO_PROFILE_DEV_DEBUG: 0
5534

@@ -60,11 +39,10 @@ concurrency:
6039

6140
jobs:
6241
# ===============================================================================================
63-
# Conventional builds, lints and tests that re-use a single cache for efficiency
42+
# Conventional builds, lints and tests
6443
# ===============================================================================================
6544

66-
# Normal cargo build that saves either the persistent trunk cache or a
67-
# single per-run cache for downstream jobs to restore immediately.
45+
# Normal cargo build that verifies the workspace compiles.
6846
build:
6947
runs-on: warp-ubuntu-latest-x64-8x
7048
steps:
@@ -77,10 +55,9 @@ jobs:
7755
run: rustup toolchain install --no-self-update
7856
- uses: WarpBuilds/rust-cache@9d0cc3090d9c87de74ea67617b246e978735b1a1 # v2.9.1
7957
with:
80-
shared-key: ${{ env.RUST_CACHE_SUFFIX }}
81-
prefix-key: ${{ env.RUST_CACHE_PREFIX }}
82-
cache-workspace-crates: true
83-
save-if: true
58+
shared-key: ${{ github.job }}
59+
prefix-key: ${{ env.CACHE_PREFIX }}
60+
save-if: ${{ env.SAVE_CACHE }}
8461
- name: cargo build
8562
run: cargo build --workspace --all-targets --locked
8663
- name: Check static linkage
@@ -124,7 +101,6 @@ jobs:
124101
clippy:
125102
name: lint - clippy
126103
runs-on: warp-ubuntu-latest-x64-8x
127-
needs: [build]
128104
steps:
129105
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
130106
with:
@@ -133,16 +109,14 @@ jobs:
133109
run: rustup toolchain install --no-self-update
134110
- uses: WarpBuilds/rust-cache@9d0cc3090d9c87de74ea67617b246e978735b1a1 # v2.9.1
135111
with:
136-
shared-key: ${{ env.RUST_CACHE_SUFFIX }}
137-
prefix-key: ${{ env.RUST_CACHE_PREFIX }}
138-
cache-workspace-crates: true
139-
save-if: false
112+
shared-key: ${{ github.job }}
113+
prefix-key: ${{ env.CACHE_PREFIX }}
114+
save-if: ${{ env.SAVE_CACHE }}
140115
- name: clippy
141116
run: cargo clippy --locked --all-targets --all-features --workspace -- -D warnings
142117

143118
tests:
144119
runs-on: warp-ubuntu-latest-x64-8x
145-
needs: [build]
146120
timeout-minutes: 30
147121
steps:
148122
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
@@ -155,10 +129,9 @@ jobs:
155129
tool: nextest@0.9.122
156130
- uses: WarpBuilds/rust-cache@9d0cc3090d9c87de74ea67617b246e978735b1a1 # v2.9.1
157131
with:
158-
shared-key: ${{ env.RUST_CACHE_SUFFIX }}
159-
prefix-key: ${{ env.RUST_CACHE_PREFIX }}
160-
cache-workspace-crates: true
161-
save-if: false
132+
shared-key: ${{ github.job }}
133+
prefix-key: ${{ env.CACHE_PREFIX }}
134+
save-if: ${{ env.SAVE_CACHE }}
162135
- name: Build tests
163136
run: cargo nextest run --all-features --workspace --no-run
164137
- name: Run tests
@@ -167,7 +140,6 @@ jobs:
167140
run: cargo test --doc --workspace --all-features
168141

169142
doc:
170-
needs: [build]
171143
runs-on: warp-ubuntu-latest-x64-8x
172144
steps:
173145
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
@@ -177,17 +149,15 @@ jobs:
177149
run: rustup toolchain install --no-self-update
178150
- uses: WarpBuilds/rust-cache@9d0cc3090d9c87de74ea67617b246e978735b1a1 # v2.9.1
179151
with:
180-
shared-key: ${{ env.RUST_CACHE_SUFFIX }}
181-
prefix-key: ${{ env.RUST_CACHE_PREFIX }}
182-
cache-workspace-crates: true
183-
save-if: false
152+
shared-key: ${{ github.job }}
153+
prefix-key: ${{ env.CACHE_PREFIX }}
154+
save-if: ${{ env.SAVE_CACHE }}
184155
- name: Build docs
185156
run: cargo doc --no-deps --workspace --all-features --locked
186157

187158
# Ensure the stress-test still functions by running some cheap benchmarks.
188159
stress-test:
189160
name: stress test
190-
needs: [build]
191161
runs-on: warp-ubuntu-latest-x64-8x
192162
timeout-minutes: 20
193163
env:
@@ -200,10 +170,9 @@ jobs:
200170
run: rustup toolchain install --no-self-update
201171
- uses: WarpBuilds/rust-cache@9d0cc3090d9c87de74ea67617b246e978735b1a1 # v2.9.1
202172
with:
203-
shared-key: ${{ env.RUST_CACHE_SUFFIX }}
204-
prefix-key: ${{ env.RUST_CACHE_PREFIX }}
205-
cache-workspace-crates: true
206-
save-if: false
173+
shared-key: ${{ github.job }}
174+
prefix-key: ${{ env.CACHE_PREFIX }}
175+
save-if: ${{ env.SAVE_CACHE }}
207176
- uses: taiki-e/install-action@055f5df8c3f65ea01cd41e9dc855becd88953486 # v2.75.18
208177
with:
209178
tool: nextest@0.9.122
@@ -216,12 +185,12 @@ jobs:
216185
cargo run --bin miden-node-stress-test seed-store \
217186
--data-directory ${{ env.DATA_DIR }} \
218187
--num-accounts 500 --public-accounts-percentage 50
219-
# TODO re-introduce
188+
# TODO re-introduce
220189
# - name: Benchmark state sync
221-
# run: |
222-
# cargo run --bin miden-node-stress-test benchmark-store \
223-
# --data-directory ${{ env.DATA_DIR }} \
224-
# --iterations 10 --concurrency 1 sync-state
190+
# run: |
191+
# cargo run --bin miden-node-stress-test benchmark-store \
192+
# --data-directory ${{ env.DATA_DIR }} \
193+
# --iterations 10 --concurrency 1 sync-state
225194
- name: Benchmark notes sync
226195
run: |
227196
cargo run --bin miden-node-stress-test benchmark-store \
@@ -233,48 +202,13 @@ jobs:
233202
--data-directory ${{ env.DATA_DIR }} \
234203
--iterations 10 --concurrency 1 sync-nullifiers --prefixes 10
235204
236-
cleanup-run-cache:
237-
name: cleanup run cache
238-
runs-on: ubuntu-24.04
239-
if: ${{ always() && github.event_name == 'pull_request' }}
240-
needs:
241-
- build
242-
- clippy
243-
- tests
244-
- doc
245-
- stress-test
246-
permissions:
247-
actions: write
248-
contents: read
249-
steps:
250-
- name: Delete PR rust cache
251-
env:
252-
GH_TOKEN: ${{ github.token }}
253-
run: |
254-
mapfile -t cache_entries < <(
255-
gh api \
256-
-H "Accept: application/vnd.github+json" \
257-
"/repos/${{ github.repository }}/actions/caches?key=${{ env.RUST_CACHE_PREFIX }}&ref=${{ github.ref }}" \
258-
--jq '.actions_caches[] | @json'
259-
)
260-
for cache_entry in "${cache_entries[@]}"; do
261-
cache_id="$(jq -r '.id' <<< "${cache_entry}")"
262-
cache_key="$(jq -r '.key' <<< "${cache_entry}")"
263-
echo "Deleting rust cache key=${cache_key}"
264-
gh api \
265-
--method DELETE \
266-
-H "Accept: application/vnd.github+json" \
267-
"/repos/${{ github.repository }}/actions/caches/${cache_id}"
268-
done
269-
270205
# ===============================================================================================
271206
# WASM related jobs
272207
# ===============================================================================================
273208

274209
# Tests the miden-remote-prover-client WASM support.
275210
#
276-
# The WASM build is incompatible with the build job's cache, thankfully this compilation is fairly
277-
# quick so we don't need a separate cache here.
211+
# The WASM build is incompatible with native build caches, so it uses a dedicated cache.
278212
client-wasm:
279213
name: wasm targets
280214
runs-on: warp-ubuntu-latest-x64-8x
@@ -284,6 +218,11 @@ jobs:
284218
persist-credentials: false
285219
- name: Rustup
286220
run: rustup toolchain install --no-self-update
221+
- uses: WarpBuilds/rust-cache@9d0cc3090d9c87de74ea67617b246e978735b1a1 # v2.9.1
222+
with:
223+
shared-key: ${{ github.job }}
224+
prefix-key: ${{ env.CACHE_PREFIX }}
225+
save-if: ${{ env.SAVE_CACHE }}
287226
- name: cargo build
288227
run: |
289228
cargo build --locked -p miden-remote-prover-client \

0 commit comments

Comments
 (0)