Skip to content

Commit 3681a5b

Browse files
ci: shard instrumentation benchmarks and add turbo cache
1 parent f696107 commit 3681a5b

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
@@ -12,8 +12,26 @@ permissions:
1212

1313
jobs:
1414
codspeed-instrumented:
15-
name: Run CodSpeed instrumented
15+
name: Run CodSpeed instrumented (${{ matrix.plugin }})
1616
runs-on: "ubuntu-latest"
17+
strategy:
18+
fail-fast: false
19+
# Shard by plugin so the benchmark groups run in parallel instead of
20+
# sequentially. CodSpeed aggregates the per-shard uploads on the commit.
21+
matrix:
22+
include:
23+
- plugin: tinybench
24+
bench: |
25+
pnpm turbo run bench --filter=@codspeed/tinybench-plugin
26+
pnpm --workspace-concurrency 1 -r bench-tinybench
27+
- plugin: vitest
28+
bench: |
29+
pnpm turbo run bench --filter=@codspeed/vitest-plugin
30+
pnpm --workspace-concurrency 1 -r bench-vitest
31+
- plugin: benchmark.js
32+
bench: |
33+
pnpm turbo run bench --filter=@codspeed/benchmark.js-plugin
34+
pnpm --workspace-concurrency 1 -r bench-benchmark-js
1735
steps:
1836
- uses: "actions/checkout@v4"
1937
with:
@@ -24,32 +42,24 @@ jobs:
2442
with:
2543
cache: pnpm
2644
node-version-file: .nvmrc
45+
- name: Restore turbo cache
46+
uses: ./.github/actions/turbo-cache
47+
with:
48+
key-suffix: ${{ matrix.plugin }}
2749
- run: pnpm install --frozen-lockfile --prefer-offline
2850
- run: pnpm turbo run build
2951

3052
- name: Run simulation benchmarks
3153
uses: CodSpeedHQ/action@main
3254
with:
3355
mode: simulation
34-
run: |
35-
pnpm turbo run bench --filter=@codspeed/tinybench-plugin
36-
pnpm turbo run bench --filter=@codspeed/vitest-plugin
37-
pnpm turbo run bench --filter=@codspeed/benchmark.js-plugin
38-
pnpm --workspace-concurrency 1 -r bench-tinybench
39-
pnpm --workspace-concurrency 1 -r bench-benchmark-js
40-
pnpm --workspace-concurrency 1 -r bench-vitest
56+
run: ${{ matrix.bench }}
4157

4258
- name: Run memory benchmarks
4359
uses: CodSpeedHQ/action@main
4460
with:
4561
mode: memory
46-
run: |
47-
pnpm turbo run bench --filter=@codspeed/tinybench-plugin
48-
pnpm turbo run bench --filter=@codspeed/vitest-plugin
49-
pnpm turbo run bench --filter=@codspeed/benchmark.js-plugin
50-
pnpm --workspace-concurrency 1 -r bench-tinybench
51-
pnpm --workspace-concurrency 1 -r bench-benchmark-js
52-
pnpm --workspace-concurrency 1 -r bench-vitest
62+
run: ${{ matrix.bench }}
5363

5464
codspeed-walltime:
5565
name: Run CodSpeed walltime
@@ -64,6 +74,8 @@ jobs:
6474
with:
6575
cache: pnpm
6676
node-version-file: .nvmrc
77+
- name: Restore turbo cache
78+
uses: ./.github/actions/turbo-cache
6779
- run: pnpm install --frozen-lockfile --prefer-offline
6880
- run: pnpm turbo run build
6981

@@ -101,6 +113,9 @@ jobs:
101113
node-version-file: .nvmrc
102114
cache: pnpm
103115

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

0 commit comments

Comments
 (0)