Skip to content

Commit 9dfa22b

Browse files
committed
ci: run pr benchmark against main
1 parent 9f9cc98 commit 9dfa22b

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

‎.github/workflows/cli-bench.yml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ concurrency:
1212
permissions: {}
1313

1414
jobs:
15-
# Runs the cheap suites against the published @nuxt/cli: startup timings
15+
# Runs the cheap suites against a baseline built from the PR's merge base:
16+
# startup timings
1617
# (interleaved, so the deltas survive runner noise even when the absolute
1718
# numbers do not), module counts and install footprint. The dev, restart
1819
# and build suites need real fixtures and minutes of wall time; run those
@@ -26,6 +27,9 @@ jobs:
2627
with:
2728
persist-credentials: false
2829

30+
- name: Fetch merge base
31+
run: git fetch --no-tags --depth=1 origin ${{ github.event.pull_request.base.sha }}
32+
2933
- run: npm i -g --force corepack && corepack enable
3034

3135
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
@@ -39,7 +43,7 @@ jobs:
3943
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4044

4145
- name: 📊 Run benchmark suites
42-
run: node --experimental-strip-types bench/run.ts --suite startup --suite modules --suite footprint --out bench-report/report.md
46+
run: node --experimental-strip-types bench/run.ts --baseline ref:${{ github.event.pull_request.base.sha }} --suite startup --suite modules --suite footprint --out bench-report/report.md
4347

4448
- name: ⏫ Upload report
4549
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7

‎bench/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Useful flags:
2020

2121
| Flag | Default | Meaning |
2222
| --- | --- | --- |
23-
|`--baseline`|`latest`| Any npm spec for `@nuxt/cli` to treat as the "before" |
23+
|`--baseline`|`latest`| Any npm spec for `@nuxt/cli` to treat as the "before", or `ref:<git-ref>` to build the baseline from a commit of this repo (CI uses the PR's base sha)|
2424
|`--suite`| all | Repeatable. One of `startup`, `modules`, `dev`, `restart`, `build`, `footprint`|
2525
|`--fixture`|`playground`, `large`| Repeatable. Which fixture to run the project-level suites against |
2626
|`--workdir`|`~/.cache/nuxt-cli-bench`| Where isolated installs and fixtures live |

‎bench/lib/targets.ts‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export interface Fixture {
2222
dir: string
2323
}
2424

25-
/** The published `@nuxt/cli` version to compare `packages/nuxt-cli` against. */
25+
/**
26+
* The baseline to compare `packages/nuxt-cli` against: an npm dist-tag or
27+
* version, or `ref:<git-ref>` to build the package from a commit of this repo.
28+
*/
2629
exportconstDEFAULT_BASELINE='latest'
2730

2831
/** Short name for table headers, e.g. `baseline v3.37.0`. */
@@ -33,19 +36,22 @@ export function shortLabel(target: Target): string {
3336
exportfunctionprepareTargets(workdir: string,baselineSpec: string=DEFAULT_BASELINE): Target[]{
3437
mkdirSync(workdir,{recursive: true})
3538

36-
consttarball=packHead(workdir)
39+
consttarball=pack(join(repoRoot,'packages/nuxt-cli'),join(workdir,'pack-head'))
40+
constbaselineInstallSpec=resolveBaselineSpec(workdir,baselineSpec)
3741

3842
consttargets: Target[]=[
3943
{id: 'baseline',label: `baseline (@nuxt/cli@${baselineSpec})`,dir: join(workdir,'baseline'),bin: '',version: '',spec: baselineSpec},
4044
{id: 'head',label: 'head (local main)',dir: join(workdir,'head'),bin: '',version: '',spec: `file:${tarball}`},
4145
]
4246

47+
constinstallSpecs: Record<string,string>={baseline: baselineInstallSpec,head: `file:${tarball}`}
48+
4349
for(consttargetoftargets){
4450
mkdirSync(target.dir,{recursive: true})
4551
writeFileSync(join(target.dir,'package.json'),`${JSON.stringify({
4652
name: `nuxt-cli-bench-${target.id}`,
4753
private: true,
48-
dependencies: {'@nuxt/cli': target.spec},
54+
dependencies: {'@nuxt/cli': installSpecs[target.id]},
4955
},null,2)}\n`)
5056
npm(['install','--no-audit','--no-fund'],target.dir)
5157
target.bin=join(target.dir,'node_modules/@nuxt/cli/bin/nuxi.mjs')
@@ -55,12 +61,29 @@ export function prepareTargets(workdir: string, baselineSpec: string = DEFAULT_B
5561
returntargets
5662
}
5763

58-
functionpackHead(workdir: string): string{
59-
constpackageDir=join(repoRoot,'packages/nuxt-cli')
64+
functionresolveBaselineSpec(workdir: string,spec: string): string{
65+
if(!spec.startsWith('ref:')){
66+
returnspec
67+
}
68+
constref=spec.slice('ref:'.length)
69+
constsha=execFileSync('git',['rev-parse',`${ref}^{commit}`],{cwd: repoRoot,encoding: 'utf8'}).trim()
70+
constdir=join(workdir,`baseline-src-${sha.slice(0,12)}`)
71+
if(!existsSync(join(dir,'package.json'))){
72+
rmSync(dir,{recursive: true,force: true})
73+
mkdirSync(dir,{recursive: true})
74+
constarchive=execFileSync('git',['archive',sha],{cwd: repoRoot,maxBuffer: 1024**3})
75+
execFileSync('tar',['-x','-C',dir],{input: archive})
76+
execFileSync('pnpm',['install'],{cwd: dir,stdio: 'ignore'})
77+
}
78+
return`file:${pack(join(dir,'packages/nuxt-cli'),join(workdir,'pack-baseline'))}`
79+
}
80+
81+
functionpack(packageDir: string,destination: string): string{
82+
mkdirSync(destination,{recursive: true})
6083
execFileSync('pnpm',['build'],{cwd: packageDir,stdio: 'ignore'})
61-
constoutput=execFileSync('npm',['pack','--json','--ignore-scripts','--pack-destination',workdir],{cwd: packageDir,encoding: 'utf8'})
84+
constoutput=execFileSync('npm',['pack','--json','--ignore-scripts','--pack-destination',destination],{cwd: packageDir,encoding: 'utf8'})
6285
const[entry]=JSON.parse(output)as{filename: string}[]
63-
returnjoin(workdir,entry!.filename)
86+
returnjoin(destination,entry!.filename)
6487
}
6588

6689
exportfunctionnpm(args: string[],cwd: string): string{

0 commit comments

Comments
 (0)