Skip to content

Commit b750913

Browse files
committed
ci: benchmark optimized setup-vp on urllib
1 parent b96225b commit b750913

1 file changed

Lines changed: 65 additions & 35 deletions

File tree

‎.github/workflows/setup-package-manager-benchmark.yml‎

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Package manager cache benchmark
33
on:
44
push:
55
branches: [codex/benchmark-package-manager-cache]
6-
paths: ['.github/workflows/setup-package-manager-benchmark.yml']
6+
paths: [".github/workflows/setup-package-manager-benchmark.yml"]
77
workflow_dispatch:
88

99
permissions:
@@ -24,20 +24,23 @@ jobs:
2424
- name: Checkout repository
2525
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
2626
with:
27+
ref: 8d14d55acb8886a2de1102f09abd008c38560c55
2728
persist-credentials: false
2829

2930
- name: Isolate benchmark caches
3031
shell: bash
3132
run: |
32-
echo "VP_HOME=$RUNNER_TEMP/urllib-pm-cache-$BENCHMARK_ID/toolchain" >> "$GITHUB_ENV"
33-
echo "pnpm_config_store_dir=$RUNNER_TEMP/urllib-pm-cache-$BENCHMARK_ID/pnpm-store" >> "$GITHUB_ENV"
33+
test ! -e "$RUNNER_TEMP/urllib-optimized-pm-cache-$BENCHMARK_ID/toolchain"
34+
test ! -e node_modules
35+
echo "VP_HOME=$RUNNER_TEMP/urllib-optimized-pm-cache-$BENCHMARK_ID/toolchain" >> "$GITHUB_ENV"
36+
echo "pnpm_config_store_dir=$RUNNER_TEMP/urllib-optimized-pm-cache-$BENCHMARK_ID/pnpm-store" >> "$GITHUB_ENV"
3437
35-
- name: Setup Vite+ preview
38+
- name: Setup Vite+ seed
3639
id: setup
37-
uses: voidzero-dev/setup-vp@85cf606c7348256a70a82b783b3cb2ff1e2b703b
40+
uses: voidzero-dev/setup-vp@06fe7ecfda756e5871867245052c17baa9b4e974
3841
with:
3942
version: 0.0.0-commit.65f9bc56f1f2d87e138013c5bcde9e7306d8eeb8
40-
node-version: '24.22.0'
43+
node-version: "24.22.0"
4144
cache: true
4245
cache-toolchain: true
4346
cache-save: true
@@ -47,7 +50,7 @@ jobs:
4750
shell: bash
4851
env:
4952
BENCHMARK_MODE: seed
50-
BENCHMARK_SAMPLE: '0'
53+
BENCHMARK_SAMPLE: "0"
5154
TOOLCHAIN_CACHE_HIT: ${{ steps.setup.outputs.toolchain-cache-hit }}
5255
DEPENDENCY_CACHE_HIT: ${{ steps.setup.outputs.cache-hit }}
5356
PM_CACHE_HIT: ${{ steps.setup.outputs.package-manager-cache-hit }}
@@ -59,25 +62,31 @@ jobs:
5962
import assert from 'node:assert/strict';
6063
import { execFileSync } from 'node:child_process';
6164
import { createHash } from 'node:crypto';
62-
import { readFileSync, writeFileSync } from 'node:fs';
65+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
6366
import path from 'node:path';
6467
const env = process.env;
65-
const preview = '0.0.0-commit.65f9bc56f1f2d87e138013c5bcde9e7306d8eeb8';
68+
const version = '0.0.0-commit.65f9bc56f1f2d87e138013c5bcde9e7306d8eeb8';
6669
const local = JSON.parse(readFileSync('node_modules/vite-plus/package.json', 'utf8'));
6770
const vite = JSON.parse(readFileSync('node_modules/vite/package.json', 'utf8'));
68-
assert.equal(local.version, preview);
71+
assert.equal(local.version, version);
6972
assert.equal(vite.name, '@voidzero-dev/vite-plus-core');
70-
assert.equal(vite.version, preview);
71-
assert.equal(env.INSTALLED_VERSION, preview);
73+
assert.equal(vite.version, version);
74+
assert.equal(env.INSTALLED_VERSION, version);
7275
assert.equal(env.INSTALLED_NODE, '24.22.0');
7376
assert.equal(env.INSTALLED_PM, '12.14.0');
7477
assert.equal(env.TOOLCHAIN_CACHE_HIT === 'true', env.BENCHMARK_MODE !== 'seed');
7578
assert.equal(env.DEPENDENCY_CACHE_HIT === 'true', env.BENCHMARK_MODE !== 'seed');
76-
assert.equal(env.PM_CACHE_HIT === 'true', env.BENCHMARK_MODE === 'hit');
79+
assert.equal(env.PM_CACHE_HIT === 'true', ['before', 'hit'].includes(env.BENCHMARK_MODE));
7780
const vp = path.join(env.VP_HOME, 'bin', process.platform === 'win32' ? 'vp.exe' : 'vp');
7881
const store = execFileSync(vp, ['pm', 'cache', 'dir'], { encoding: 'utf8' }).trim();
7982
assert.equal(path.resolve(store), path.resolve(env.pnpm_config_store_dir, 'v11'));
83+
const managerBin = path.join(env.VP_HOME, 'package_manager/pnpm/12.14.0/pnpm/bin');
84+
const binary = ['pnpm.native.exe', 'pnpm.native', 'pnpm.cjs'].map(name => path.join(managerBin, name)).find(file => existsSync(file));
85+
assert.ok(binary, 'Expected a managed pnpm executable');
86+
const checkout = execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
87+
assert.equal(checkout, '8d14d55acb8886a2de1102f09abd008c38560c55');
8088
const result = {
89+
checkout,
8190
mode: env.BENCHMARK_MODE,
8291
sample: Number(env.BENCHMARK_SAMPLE),
8392
os: env.RUNNER_OS,
@@ -91,7 +100,7 @@ jobs:
91100
packageManager: env.INSTALLED_PM,
92101
packageManagerInfo: JSON.parse(execFileSync(vp, ['env', 'current', '--json'], { encoding: 'utf8' })).package_manager,
93102
packageManagerCacheHit: env.PM_CACHE_HIT === 'true',
94-
packageManagerBinaryHash: createHash('sha256').update(readFileSync(path.join(env.VP_HOME, 'package_manager/pnpm/12.14.0/pnpm/bin', process.platform === 'win32' ? 'pnpm.native.exe' : 'pnpm.native'))).digest('hex'),
103+
packageManagerBinaryHash: createHash('sha256').update(readFileSync(binary)).digest('hex'),
95104
toolchainCacheHit: env.TOOLCHAIN_CACHE_HIT === 'true',
96105
dependencyCacheHit: env.DEPENDENCY_CACHE_HIT === 'true',
97106
dependencyStore: store,
@@ -119,7 +128,7 @@ jobs:
119128
matrix:
120129
sample: [1, 2, 3, 4, 5, 6]
121130
os: [ubuntu-latest, macos-latest, windows-latest]
122-
mode: [before, hit]
131+
mode: [base, before, hit]
123132
runs-on: ${{ matrix.os }}
124133
timeout-minutes: 15
125134
env:
@@ -128,21 +137,36 @@ jobs:
128137
- name: Checkout repository
129138
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
130139
with:
140+
ref: 8d14d55acb8886a2de1102f09abd008c38560c55
131141
persist-credentials: false
132142

133143
- name: Isolate benchmark caches
134144
shell: bash
135145
run: |
136-
echo "VP_HOME=$RUNNER_TEMP/urllib-pm-cache-$BENCHMARK_ID/toolchain" >> "$GITHUB_ENV"
137-
echo "pnpm_config_store_dir=$RUNNER_TEMP/urllib-pm-cache-$BENCHMARK_ID/pnpm-store" >> "$GITHUB_ENV"
146+
test ! -e "$RUNNER_TEMP/urllib-optimized-pm-cache-$BENCHMARK_ID/toolchain"
147+
test ! -e node_modules
148+
echo "VP_HOME=$RUNNER_TEMP/urllib-optimized-pm-cache-$BENCHMARK_ID/toolchain" >> "$GITHUB_ENV"
149+
echo "pnpm_config_store_dir=$RUNNER_TEMP/urllib-optimized-pm-cache-$BENCHMARK_ID/pnpm-store" >> "$GITHUB_ENV"
138150
139-
- name: Setup Vite+ before
151+
- name: Setup Vite+ base
140152
id: baseline
141-
if: matrix.mode == 'before'
153+
if: matrix.mode == 'base'
142154
uses: voidzero-dev/setup-vp@c025a93923d2f9c524652d786386d11065fc3e8f
143155
with:
144156
version: 0.0.0-commit.65f9bc56f1f2d87e138013c5bcde9e7306d8eeb8
145-
node-version: '24.22.0'
157+
node-version: "24.22.0"
158+
cache: true
159+
cache-toolchain: true
160+
cache-save: false
161+
sfw: true
162+
163+
- name: Setup Vite+ before
164+
id: previous
165+
if: matrix.mode == 'before'
166+
uses: voidzero-dev/setup-vp@85cf606c7348256a70a82b783b3cb2ff1e2b703b
167+
with:
168+
version: 0.0.0-commit.65f9bc56f1f2d87e138013c5bcde9e7306d8eeb8
169+
node-version: "24.22.0"
146170
cache: true
147171
cache-toolchain: true
148172
cache-save: false
@@ -151,10 +175,10 @@ jobs:
151175
- name: Setup Vite+ after
152176
id: setup
153177
if: matrix.mode == 'hit'
154-
uses: voidzero-dev/setup-vp@85cf606c7348256a70a82b783b3cb2ff1e2b703b
178+
uses: voidzero-dev/setup-vp@06fe7ecfda756e5871867245052c17baa9b4e974
155179
with:
156180
version: 0.0.0-commit.65f9bc56f1f2d87e138013c5bcde9e7306d8eeb8
157-
node-version: '24.22.0'
181+
node-version: "24.22.0"
158182
cache: true
159183
cache-toolchain: true
160184
cache-save: false
@@ -165,36 +189,42 @@ jobs:
165189
env:
166190
BENCHMARK_MODE: ${{ matrix.mode }}
167191
BENCHMARK_SAMPLE: ${{ matrix.sample }}
168-
TOOLCHAIN_CACHE_HIT: ${{ steps.setup.outputs.toolchain-cache-hit || steps.baseline.outputs.toolchain-cache-hit }}
169-
DEPENDENCY_CACHE_HIT: ${{ steps.setup.outputs.cache-hit || steps.baseline.outputs.cache-hit }}
170-
PM_CACHE_HIT: ${{ steps.setup.outputs.package-manager-cache-hit || steps.baseline.outputs.package-manager-cache-hit }}
171-
INSTALLED_VERSION: ${{ steps.setup.outputs.version || steps.baseline.outputs.version }}
172-
INSTALLED_NODE: ${{ steps.setup.outputs.node-version || steps.baseline.outputs.node-version }}
173-
INSTALLED_PM: ${{ steps.setup.outputs.package-manager-version || steps.baseline.outputs.package-manager-version }}
192+
TOOLCHAIN_CACHE_HIT: ${{ steps.setup.outputs.toolchain-cache-hit || steps.previous.outputs.toolchain-cache-hit || steps.baseline.outputs.toolchain-cache-hit }}
193+
DEPENDENCY_CACHE_HIT: ${{ steps.setup.outputs.cache-hit || steps.previous.outputs.cache-hit || steps.baseline.outputs.cache-hit }}
194+
PM_CACHE_HIT: ${{ steps.setup.outputs.package-manager-cache-hit || steps.previous.outputs.package-manager-cache-hit || steps.baseline.outputs.package-manager-cache-hit }}
195+
INSTALLED_VERSION: ${{ steps.setup.outputs.version || steps.previous.outputs.version || steps.baseline.outputs.version }}
196+
INSTALLED_NODE: ${{ steps.setup.outputs.node-version || steps.previous.outputs.node-version || steps.baseline.outputs.node-version }}
197+
INSTALLED_PM: ${{ steps.setup.outputs.package-manager-version || steps.previous.outputs.package-manager-version || steps.baseline.outputs.package-manager-version }}
174198
run: |
175199
node --input-type=module <<'JS'
176200
import assert from 'node:assert/strict';
177201
import { execFileSync } from 'node:child_process';
178202
import { createHash } from 'node:crypto';
179-
import { readFileSync, writeFileSync } from 'node:fs';
203+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
180204
import path from 'node:path';
181205
const env = process.env;
182-
const preview = '0.0.0-commit.65f9bc56f1f2d87e138013c5bcde9e7306d8eeb8';
206+
const version = '0.0.0-commit.65f9bc56f1f2d87e138013c5bcde9e7306d8eeb8';
183207
const local = JSON.parse(readFileSync('node_modules/vite-plus/package.json', 'utf8'));
184208
const vite = JSON.parse(readFileSync('node_modules/vite/package.json', 'utf8'));
185-
assert.equal(local.version, preview);
209+
assert.equal(local.version, version);
186210
assert.equal(vite.name, '@voidzero-dev/vite-plus-core');
187-
assert.equal(vite.version, preview);
188-
assert.equal(env.INSTALLED_VERSION, preview);
211+
assert.equal(vite.version, version);
212+
assert.equal(env.INSTALLED_VERSION, version);
189213
assert.equal(env.INSTALLED_NODE, '24.22.0');
190214
assert.equal(env.INSTALLED_PM, '12.14.0');
191215
assert.equal(env.TOOLCHAIN_CACHE_HIT === 'true', env.BENCHMARK_MODE !== 'seed');
192216
assert.equal(env.DEPENDENCY_CACHE_HIT === 'true', env.BENCHMARK_MODE !== 'seed');
193-
assert.equal(env.PM_CACHE_HIT === 'true', env.BENCHMARK_MODE === 'hit');
217+
assert.equal(env.PM_CACHE_HIT === 'true', ['before', 'hit'].includes(env.BENCHMARK_MODE));
194218
const vp = path.join(env.VP_HOME, 'bin', process.platform === 'win32' ? 'vp.exe' : 'vp');
195219
const store = execFileSync(vp, ['pm', 'cache', 'dir'], { encoding: 'utf8' }).trim();
196220
assert.equal(path.resolve(store), path.resolve(env.pnpm_config_store_dir, 'v11'));
221+
const managerBin = path.join(env.VP_HOME, 'package_manager/pnpm/12.14.0/pnpm/bin');
222+
const binary = ['pnpm.native.exe', 'pnpm.native', 'pnpm.cjs'].map(name => path.join(managerBin, name)).find(file => existsSync(file));
223+
assert.ok(binary, 'Expected a managed pnpm executable');
224+
const checkout = execFileSync('git', ['rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
225+
assert.equal(checkout, '8d14d55acb8886a2de1102f09abd008c38560c55');
197226
const result = {
227+
checkout,
198228
mode: env.BENCHMARK_MODE,
199229
sample: Number(env.BENCHMARK_SAMPLE),
200230
os: env.RUNNER_OS,
@@ -208,7 +238,7 @@ jobs:
208238
packageManager: env.INSTALLED_PM,
209239
packageManagerInfo: JSON.parse(execFileSync(vp, ['env', 'current', '--json'], { encoding: 'utf8' })).package_manager,
210240
packageManagerCacheHit: env.PM_CACHE_HIT === 'true',
211-
packageManagerBinaryHash: createHash('sha256').update(readFileSync(path.join(env.VP_HOME, 'package_manager/pnpm/12.14.0/pnpm/bin', process.platform === 'win32' ? 'pnpm.native.exe' : 'pnpm.native'))).digest('hex'),
241+
packageManagerBinaryHash: createHash('sha256').update(readFileSync(binary)).digest('hex'),
212242
toolchainCacheHit: env.TOOLCHAIN_CACHE_HIT === 'true',
213243
dependencyCacheHit: env.DEPENDENCY_CACHE_HIT === 'true',
214244
dependencyStore: store,

0 commit comments

Comments
 (0)