Skip to content

Commit 37871a8

Browse files
ci: shard instrumentation benchmarks and add turbo cache
1 parent 7cd0fe6 commit 37871a8

3 files changed

Lines changed: 64 additions & 15 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Turbo cache
2+
description: >
3+
Restore and persist the local Turbo cache (.turbo/cache) across CI runs.
4+
Keyed on the OS, CPU arch and lockfile, with the commit SHA as a unique suffix
5+
so each run writes a fresh entry while falling back to the closest prior cache.
6+
Arch is part of the key because Turbo does not hash it into the native addon
7+
build, so an x64 cache must not restore into an arm64 run. Turbo validates
8+
restored entries by content hash, so a partial restore is always safe.
9+
10+
inputs:
11+
key-suffix:
12+
description: >
13+
Extra discriminator folded into the cache key. Set it when a job builds
14+
under a config Turbo does not hash itself (e.g. a specific Node version
15+
for the native addon ABI) so its cache stays separate.
16+
required: false
17+
default: ""
18+
19+
runs:
20+
using: composite
21+
steps:
22+
- uses: actions/cache@v4
23+
with:
24+
path: .turbo/cache
25+
key: turbo-${{ runner.os }}-${{ runner.arch }}-${{ inputs.key-suffix }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
26+
restore-keys: |
27+
turbo-${{ runner.os }}-${{ runner.arch }}-${{ inputs.key-suffix }}-${{ hashFiles('pnpm-lock.yaml') }}-
28+
turbo-${{ runner.os }}-${{ runner.arch }}-${{ inputs.key-suffix }}-

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
with:
2323
cache: pnpm
2424
node-version-file: .nvmrc
25+
- name: Restore turbo cache
26+
uses: ./.github/actions/turbo-cache
2527
- run: pnpm install --frozen-lockfile --prefer-offline
2628
- run: pnpm turbo run lint typecheck test
2729

@@ -60,6 +62,10 @@ jobs:
6062
with:
6163
cache: pnpm
6264
node-version: ${{ matrix.node-version }}
65+
- name: Restore turbo cache
66+
uses: ./.github/actions/turbo-cache
67+
with:
68+
key-suffix: node${{ matrix.node-version }}
6369
- run: pnpm install --frozen-lockfile --prefer-offline
6470
- run: pnpm turbo run build
6571

@@ -94,6 +100,8 @@ jobs:
94100
with:
95101
cache: pnpm
96102
node-version-file: .nvmrc
103+
- name: Restore turbo cache
104+
uses: ./.github/actions/turbo-cache
97105
- run: pnpm install --frozen-lockfile --prefer-offline
98106
- run: pnpm turbo run build
99107

.github/workflows/codspeed.yml

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,26 @@ on:
88

99
jobs:
1010
codspeed-instrumented:
11-
name: Run CodSpeed instrumented
11+
name: Run CodSpeed instrumented (${{ matrix.plugin }})
1212
runs-on: "ubuntu-latest"
13+
strategy:
14+
fail-fast: false
15+
# Shard by plugin so the benchmark groups run in parallel instead of
16+
# sequentially. CodSpeed aggregates the per-shard uploads on the commit.
17+
matrix:
18+
include:
19+
- plugin: tinybench
20+
bench: |
21+
pnpm turbo run bench --filter=@codspeed/tinybench-plugin
22+
pnpm --workspace-concurrency 1 -r bench-tinybench
23+
- plugin: vitest
24+
bench: |
25+
pnpm turbo run bench --filter=@codspeed/vitest-plugin
26+
pnpm --workspace-concurrency 1 -r bench-vitest
27+
- plugin: benchmark.js
28+
bench: |
29+
pnpm turbo run bench --filter=@codspeed/benchmark.js-plugin
30+
pnpm --workspace-concurrency 1 -r bench-benchmark-js
1331
steps:
1432
- uses: "actions/checkout@v4"
1533
with:
@@ -20,32 +38,22 @@ jobs:
2038
with:
2139
cache: pnpm
2240
node-version-file: .nvmrc
41+
- name: Restore turbo cache
42+
uses: ./.github/actions/turbo-cache
2343
- run: pnpm install --frozen-lockfile --prefer-offline
2444
- run: pnpm turbo run build
2545

2646
- name: Run simulation benchmarks
2747
uses: CodSpeedHQ/action@main
2848
with:
2949
mode: simulation
30-
run: |
31-
pnpm turbo run bench --filter=@codspeed/tinybench-plugin
32-
pnpm turbo run bench --filter=@codspeed/vitest-plugin
33-
pnpm turbo run bench --filter=@codspeed/benchmark.js-plugin
34-
pnpm --workspace-concurrency 1 -r bench-tinybench
35-
pnpm --workspace-concurrency 1 -r bench-benchmark-js
36-
pnpm --workspace-concurrency 1 -r bench-vitest
50+
run: ${{ matrix.bench }}
3751

3852
- name: Run memory benchmarks
3953
uses: CodSpeedHQ/action@main
4054
with:
4155
mode: memory
42-
run: |
43-
pnpm turbo run bench --filter=@codspeed/tinybench-plugin
44-
pnpm turbo run bench --filter=@codspeed/vitest-plugin
45-
pnpm turbo run bench --filter=@codspeed/benchmark.js-plugin
46-
pnpm --workspace-concurrency 1 -r bench-tinybench
47-
pnpm --workspace-concurrency 1 -r bench-benchmark-js
48-
pnpm --workspace-concurrency 1 -r bench-vitest
56+
run: ${{ matrix.bench }}
4957

5058
codspeed-walltime:
5159
name: Run CodSpeed walltime
@@ -60,6 +68,8 @@ jobs:
6068
with:
6169
cache: pnpm
6270
node-version-file: .nvmrc
71+
- name: Restore turbo cache
72+
uses: ./.github/actions/turbo-cache
6373
- run: pnpm install --frozen-lockfile --prefer-offline
6474
- run: pnpm turbo run build
6575

@@ -100,6 +110,9 @@ jobs:
100110
node-version-file: .nvmrc
101111
cache: pnpm
102112

113+
- name: Restore turbo cache
114+
uses: ./.github/actions/turbo-cache
115+
103116
- name: Install repo dependencies
104117
run: pnpm install --frozen-lockfile --prefer-offline
105118

0 commit comments

Comments
 (0)