Skip to content

Commit 7ad0d75

Browse files
ci: shard instrumentation benchmarks and add turbo cache
1 parent bd08cf6 commit 7ad0d75

3 files changed

Lines changed: 66 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: 30 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,24 @@ jobs:
2038
with:
2139
cache: pnpm
2240
node-version-file: .nvmrc
41+
- name: Restore turbo cache
42+
uses: ./.github/actions/turbo-cache
43+
with:
44+
key-suffix: ${{ matrix.plugin }}
2345
- run: pnpm install --frozen-lockfile --prefer-offline
2446
- run: pnpm turbo run build
2547

2648
- name: Run simulation benchmarks
2749
uses: CodSpeedHQ/action@main
2850
with:
2951
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
52+
run: ${{ matrix.bench }}
3753

3854
- name: Run memory benchmarks
3955
uses: CodSpeedHQ/action@main
4056
with:
4157
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
58+
run: ${{ matrix.bench }}
4959

5060
codspeed-walltime:
5161
name: Run CodSpeed walltime
@@ -60,6 +70,8 @@ jobs:
6070
with:
6171
cache: pnpm
6272
node-version-file: .nvmrc
73+
- name: Restore turbo cache
74+
uses: ./.github/actions/turbo-cache
6375
- run: pnpm install --frozen-lockfile --prefer-offline
6476
- run: pnpm turbo run build
6577

@@ -100,6 +112,9 @@ jobs:
100112
node-version-file: .nvmrc
101113
cache: pnpm
102114

115+
- name: Restore turbo cache
116+
uses: ./.github/actions/turbo-cache
117+
103118
- name: Install repo dependencies
104119
run: pnpm install --frozen-lockfile --prefer-offline
105120

0 commit comments

Comments
 (0)