-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ci: omit unchanged bundle size scenarios #7856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+184
−22
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import assert from 'node:assert/strict' | ||
| import { execFile } from 'node:child_process' | ||
| import { promises as fs } from 'node:fs' | ||
| import os from 'node:os' | ||
| import path from 'node:path' | ||
| import { promisify } from 'node:util' | ||
| import test from 'node:test' | ||
|
|
||
| const execFileAsync = promisify(execFile) | ||
| const reportScript = new URL('./pr-report.mjs', import.meta.url) | ||
|
|
||
| function metric(id, gzipBytes) { | ||
| return { | ||
| id, | ||
| gzipBytes, | ||
| rawBytes: gzipBytes * 3, | ||
| brotliBytes: gzipBytes - 100, | ||
| initialGzipBytes: gzipBytes - 10, | ||
| } | ||
| } | ||
|
|
||
| async function generateReport({ current, baseline, history, baseSha }) { | ||
| const fixtureDir = await fs.mkdtemp( | ||
| path.join(os.tmpdir(), 'bundle-size-pr-report-'), | ||
| ) | ||
|
|
||
| try { | ||
| const currentPath = path.join(fixtureDir, 'current.json') | ||
| const outputPath = path.join(fixtureDir, 'report.md') | ||
| const args = [ | ||
| reportScript.pathname, | ||
| '--current', | ||
| currentPath, | ||
| '--output', | ||
| outputPath, | ||
| ] | ||
|
|
||
| await fs.writeFile(currentPath, JSON.stringify(current)) | ||
|
|
||
| if (baseline) { | ||
| const baselinePath = path.join(fixtureDir, 'baseline.json') | ||
| await fs.writeFile(baselinePath, JSON.stringify(baseline)) | ||
| args.push('--baseline', baselinePath) | ||
| } | ||
|
|
||
| if (history) { | ||
| const historyPath = path.join(fixtureDir, 'history.json') | ||
| await fs.writeFile(historyPath, JSON.stringify(history)) | ||
| args.push('--history', historyPath) | ||
| } | ||
|
|
||
| if (baseSha) { | ||
| args.push('--base-sha', baseSha) | ||
| } | ||
|
|
||
| await execFileAsync(process.execPath, args) | ||
| return await fs.readFile(outputPath, 'utf8') | ||
| } finally { | ||
| await fs.rm(fixtureDir, { recursive: true, force: true }) | ||
| } | ||
| } | ||
|
|
||
| function currentJson(metrics) { | ||
| return { | ||
| benchmarkName: 'Bundle Size (gzip)', | ||
| measuredAt: '2026-07-19T09:45:56.787Z', | ||
| sha: '126aa13f296b1234', | ||
| metrics, | ||
| } | ||
| } | ||
|
|
||
| test('renders a concise message when no measured scenario changed', async () => { | ||
| const current = currentJson([metric('react-router.minimal', 1_000)]) | ||
| const report = await generateReport({ current, baseline: current }) | ||
|
|
||
| assert.equal( | ||
| report, | ||
| '<!-- bundle-size-benchmark -->\n## Bundle Size Benchmarks\n\nThis pull request does not affect bundle size in any measured scenario.\n', | ||
| ) | ||
| }) | ||
|
|
||
| test('renders only scenarios that changed against the historical baseline', async () => { | ||
| const current = currentJson([ | ||
| metric('react-router.minimal', 1_000), | ||
| metric('react-router.full', 1_200), | ||
| ]) | ||
| const history = { | ||
| entries: { | ||
| [current.benchmarkName]: [ | ||
| { | ||
| commit: { id: 'baseline-sha' }, | ||
| benches: [ | ||
| { name: 'react-router.minimal', value: 1_000 }, | ||
| { name: 'react-router.full', value: 1_100 }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| } | ||
| const report = await generateReport({ | ||
| current, | ||
| history, | ||
| baseSha: 'baseline-sha', | ||
| }) | ||
|
|
||
| assert.match( | ||
| report, | ||
| /The following scenarios have bundle-size changes compared with the baseline:/, | ||
| ) | ||
| assert.doesNotMatch(report, /`react-router\.minimal`/) | ||
| assert.match( | ||
| report, | ||
| /\| `react-router\.full` \| 1\.17 KiB \| \+100 B \(\+9\.09%\) \|/, | ||
| ) | ||
| }) | ||
|
|
||
| test('keeps scenarios that do not have baseline data visible', async () => { | ||
| const current = currentJson([ | ||
| metric('react-router.minimal', 1_000), | ||
| metric('new-scenario', 900), | ||
| ]) | ||
| const baseline = currentJson([metric('react-router.minimal', 1_000)]) | ||
| const report = await generateReport({ current, baseline }) | ||
|
|
||
| assert.match( | ||
| report, | ||
| /The following scenarios have bundle-size changes or lack baseline data for comparison:/, | ||
| ) | ||
| assert.doesNotMatch(report, /`react-router\.minimal`/) | ||
| assert.match(report, /\| `new-scenario` \| 900 B \| n\/a \|/) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/router
Length of output: 4428
🏁 Script executed:
Repository: TanStack/router
Length of output: 1198
🏁 Script executed:
Repository: TanStack/router
Length of output: 6049
🏁 Script executed:
Repository: TanStack/router
Length of output: 572
Rows can disappear when only non-gzip metrics change
scripts/benchmarks/bundle-size/pr-report.mjs:271-280The skip check only compares
metric.gzipBytesto the baseline. Since the table also showsraw,brotli, andinitial, a PR can report “does not affect bundle size in any measured scenario” even when those displayed values changed. Consider including them in the change check, or remove them if gzip is the only signal.🤖 Prompt for AI Agents