Skip to content

Commit c54fb1b

Browse files
authored
Improve caching on CI (#5772)
* Try to build WASM on Ubuntu * Align cache keys for performance report/REPL They can share the cache with the corresponding build jobs. * Only save caches on master
1 parent 5d37778 commit c54fb1b

File tree

3 files changed

+70
-42
lines changed

3 files changed

+70
-42
lines changed

.github/workflows/build-and-tests.yml

+51-23
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ jobs:
3636
uses: actions/setup-node@v4
3737
with:
3838
node-version: 22
39-
- name: Cache Node Modules
39+
- name: Restore Node dependencies cache
4040
id: cache-node-modules
41-
uses: actions/cache@v4
41+
uses: actions/cache/restore@v4
4242
with:
4343
path: node_modules
4444
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
45-
- name: Install dependencies
45+
- name: Install Node dependencies
4646
if: steps.cache-node-modules.outputs.cache-hit != 'true'
4747
run: npm ci --ignore-scripts
4848
- name: Lint
@@ -64,8 +64,8 @@ jobs:
6464
matrix:
6565
settings:
6666
# WASM
67-
- host: windows-latest
68-
target: x86_64-pc-windows-msvc
67+
- host: ubuntu-latest
68+
target: wasm32-unknown-unknown
6969
name: wasm
7070
is-wasm-build: true
7171
build: >-
@@ -75,8 +75,8 @@ jobs:
7575
path: |
7676
wasm/
7777
.empty
78-
- host: windows-latest
79-
target: x86_64-pc-windows-msvc
78+
- host: ubuntu-latest
79+
target: wasm32-unknown-unknown
8080
name: wasm-node
8181
is-wasm-build: true
8282
build: >-
@@ -222,8 +222,8 @@ jobs:
222222
with:
223223
toolchain: stable
224224
targets: ${{ matrix.settings.target }}
225-
- name: Cache cargo
226-
uses: actions/cache@v4
225+
- name: Restore Cargo cache
226+
uses: actions/cache/restore@v4
227227
with:
228228
path: |
229229
~/.cargo/registry/index/
@@ -241,15 +241,21 @@ jobs:
241241
run: ${{ matrix.settings.setup }}
242242
if: ${{ matrix.settings.setup }}
243243
shell: bash
244-
- name: Cache Node Modules
244+
- name: Restore Node dependencies cache
245245
id: cache-node-modules
246-
uses: actions/cache@v4
246+
uses: actions/cache/restore@v4
247247
with:
248248
path: node_modules
249249
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
250-
- name: Install dependencies
250+
- name: Install Node dependencies
251251
if: steps.cache-node-modules.outputs.cache-hit != 'true'
252252
run: npm ci --ignore-scripts
253+
- name: Save Node dependencies cache
254+
if: steps.cache-node-modules.outputs.cache-hit != 'true' && github.ref == 'refs/heads/master'
255+
uses: actions/cache/save@v4
256+
with:
257+
path: node_modules
258+
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
253259
- name: Build in docker
254260
uses: addnab/docker-run-action@v3
255261
if: ${{ matrix.settings.docker }}
@@ -261,6 +267,17 @@ jobs:
261267
run: ${{ matrix.settings.build }}
262268
if: ${{ !matrix.settings.docker }}
263269
shell: bash
270+
- name: Save Cargo cache
271+
if: github.ref == 'refs/heads/master'
272+
uses: actions/cache/save@v4
273+
with:
274+
path: |
275+
~/.cargo/registry/index/
276+
~/.cargo/registry/cache/
277+
~/.cargo/git/db/
278+
.cargo-cache
279+
rust/target/
280+
key: ${{ matrix.settings.name || matrix.settings.target }}-cargo-${{ matrix.settings.host }}-${{ hashFiles('rust/Cargo.lock') }}
264281
- name: Upload wasm artifact
265282
uses: actions/upload-artifact@v4
266283
with:
@@ -295,8 +312,8 @@ jobs:
295312
steps:
296313
- name: Checkout Commit
297314
uses: actions/checkout@v4
298-
- name: Cache cargo
299-
uses: actions/cache@v4
315+
- name: Restore Cargo cache
316+
uses: actions/cache/restore@v4
300317
with:
301318
path: |
302319
~/.cargo/registry/index/
@@ -317,6 +334,17 @@ jobs:
317334
sudo pkg install -y node npm rust
318335
npm ci --ignore-scripts
319336
npm run build:napi -- --release --target ${{ matrix.settings.target }}
337+
- name: Save Cargo cache
338+
if: github.ref == 'refs/heads/master'
339+
uses: actions/cache/save@v4
340+
with:
341+
path: |
342+
~/.cargo/registry/index/
343+
~/.cargo/registry/cache/
344+
~/.cargo/git/db/
345+
.cargo-cache
346+
rust/target/
347+
key: ${{ matrix.settings.target }}-cargo-${{ hashFiles('rust/Cargo.lock') }}
320348
- name: Upload napi artifact
321349
uses: actions/upload-artifact@v4
322350
with:
@@ -365,13 +393,13 @@ jobs:
365393
steps:
366394
- name: Checkout Commit
367395
uses: actions/checkout@v4
368-
- name: Cache Node Modules
396+
- name: Restore Node dependencies cache
369397
id: cache-node-modules
370-
uses: actions/cache@v4
398+
uses: actions/cache/restore@v4
371399
with:
372400
path: node_modules
373401
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
374-
- name: Install dependencies
402+
- name: Install Node dependencies
375403
if: steps.cache-node-modules.outputs.cache-hit != 'true'
376404
run: npm ci --ignore-scripts
377405
- name: Build JS
@@ -460,13 +488,13 @@ jobs:
460488
with:
461489
node-version: ${{ matrix.node }}
462490
check-latest: true
463-
- name: Cache Node Modules
491+
- name: Restore Node dependencies cache
464492
id: cache-node-modules
465-
uses: actions/cache@v4
493+
uses: actions/cache/restore@v4
466494
with:
467495
path: node_modules
468496
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
469-
- name: Install dependencies
497+
- name: Install Node dependencies
470498
if: steps.cache-node-modules.outputs.cache-hit != 'true'
471499
run: npm ci --ignore-scripts
472500
- name: Download napi artifacts
@@ -515,13 +543,13 @@ jobs:
515543
with:
516544
node-version: ${{ matrix.node }}
517545
check-latest: true
518-
- name: Cache Node Modules
546+
- name: Restore Node dependencies cache
519547
id: cache-node-modules
520-
uses: actions/cache@v4
548+
uses: actions/cache/restore@v4
521549
with:
522550
path: node_modules
523551
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
524-
- name: Install dependencies
552+
- name: Install Node dependencies
525553
if: steps.cache-node-modules.outputs.cache-hit != 'true'
526554
run: npm ci --ignore-scripts
527555
- name: Download all artifacts

.github/workflows/performance-report.yml

+13-13
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,28 @@ jobs:
3737
with:
3838
toolchain: stable
3939
targets: x86_64-unknown-linux-gnu
40-
- name: Cache cargo
41-
uses: actions/cache@v4
40+
- name: Restore Cargo cache
41+
uses: actions/cache/restore@v4
4242
with:
4343
path: |
4444
~/.cargo/registry/index/
4545
~/.cargo/registry/cache/
4646
~/.cargo/git/db/
4747
.cargo-cache
4848
rust/target/
49-
key: cargo-cache-${{ hashFiles('rust/Cargo.lock') }}
50-
restore-keys: cargo-cache
49+
key: x86_64-unknown-linux-gnu-cargo-ubuntu-latest-${{ hashFiles('rust/Cargo.lock') }}
50+
restore-keys: x86_64-unknown-linux-gnu-cargo-ubuntu-latest
5151
- name: Setup Node
5252
uses: actions/setup-node@v4
5353
with:
5454
node-version: 18
55-
- name: Cache Node Modules
55+
- name: Restore Node dependencies cache
5656
id: cache-node-modules
57-
uses: actions/cache@v4
57+
uses: actions/cache/restore@v4
5858
with:
5959
path: node_modules
6060
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}
61-
- name: Install dependencies
61+
- name: Install Node dependencies
6262
if: steps.cache-node-modules.outputs.cache-hit != 'true'
6363
run: npm ci --ignore-scripts
6464
- name: Build artefacts 123
@@ -86,24 +86,24 @@ jobs:
8686
with:
8787
toolchain: stable
8888
targets: x86_64-unknown-linux-gnu
89-
- name: Cache cargo
90-
uses: actions/cache@v4
89+
- name: Restore Cargo cache
90+
uses: actions/cache/restore@v4
9191
with:
9292
path: |
9393
~/.cargo/registry/index/
9494
~/.cargo/registry/cache/
9595
~/.cargo/git/db/
9696
.cargo-cache
9797
rust/target/
98-
key: cargo-cache-${{ hashFiles('rust/Cargo.lock') }}
99-
restore-keys: cargo-cache
98+
key: x86_64-unknown-linux-gnu-cargo-ubuntu-latest-${{ hashFiles('rust/Cargo.lock') }}
99+
restore-keys: x86_64-unknown-linux-gnu-cargo-ubuntu-latest
100100
- name: Setup Node
101101
uses: actions/setup-node@v4
102102
with:
103103
node-version: 18
104-
- name: Cache Node Modules
104+
- name: Restore Node dependencies cache
105105
id: cache-node-modules
106-
uses: actions/cache@v4
106+
uses: actions/cache/restore@v4
107107
with:
108108
path: node_modules
109109
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}

.github/workflows/repl-artefacts.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,24 @@ jobs:
3232
with:
3333
toolchain: stable
3434
targets: wasm32-unknown-unknown
35-
- name: Cache cargo
36-
uses: actions/cache@v4
35+
- name: Restore Cargo cache
36+
uses: actions/cache/restore@v4
3737
with:
3838
path: |
3939
~/.cargo/registry/index/
4040
~/.cargo/registry/cache/
4141
~/.cargo/git/db/
4242
.cargo-cache
4343
rust/target/
44-
key: cargo-cache-${{ hashFiles('rust/Cargo.lock') }}
45-
restore-keys: cargo-cache
44+
key: wasm-cargo-ubuntu-latest-${{ hashFiles('rust/Cargo.lock') }}
45+
restore-keys: wasm-cargo-ubuntu-latest
4646
- name: Setup Node
4747
uses: actions/setup-node@v4
4848
with:
4949
node-version: 18
50-
- name: Cache Node Modules
50+
- name: Restore Node dependencies cache
5151
id: cache-node-modules
52-
uses: actions/cache@v4
52+
uses: actions/cache/restore@v4
5353
with:
5454
path: node_modules
5555
key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }}

0 commit comments

Comments
 (0)