Repository navigation
ci: report published package size and new runtime dependencies on each PR, in the build job - #9161
Conversation
…h PR, in the build job Measures every published package's npm download and unpacked size in build-storybook, after its build, and compares it with the merge base's measurement that Main now keeps for 14 days. Adds a Published Package Size section to the PR report and the job summary, and fails the job when a package's download grows more than 5% (and at least 1 KB) unless the PR description has a 'Size budget:' line.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report
📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: Accessibility did not run on this pull request; add Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Approval is on hold for one decision. No current spec states the new merge-blocking package-size budget: build fails on more than 5% and at least 1 KB of download growth unless the description has a Size budget: line. An engineering owner needs to adopt it as written or have it recorded in a spec first, and records that decision by commenting /approve-spec followed by the full head SHA on this pull request (the author may do this as an engineering owner). Separately from that decision, these need fixing:
- The merge base comes from a 50-commit fetch with no deepen fallback (
ci.yml:1047), so a branch 50 or more main commits behind gets no budget, and the report blames a 14-day age instead. filesandbudget.packedPercentare written into the PR comment withoutnum(), unlike every other report value (package-size.js:272-297).- The
pathsscope (ci.yml:907) skips the measurement when only roottsconfig.jsonor the rootscripts/that package builds run change, which AST-030 FR13 treats as shared infrastructure. - The base lookup copies
size-base's steps and lost their deepen fallback along the way, so one shared helper would keep the two in step.
[Automated review]
| if: steps.scope.outputs.docsite_only != 'true' && steps.scope.outputs.spec_only != 'true' && steps.scope.outputs.tooling_only != 'true' && steps.package-size.outcome == 'success' | ||
| env: | ||
| BASE_REF: ${{ github.base_ref }} | ||
| run: echo "sha=$(git merge-base "origin/$BASE_REF" HEAD || true)" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
This merge base comes from the 50-commit fetches at lines 924 and 934 and has no fallback. Once main is 50 or more commits past the fork point it comes back empty, the verdict is no-base, and build passes whatever the growth, while the report blames a 14-day age. size-base deepens by 200 when this fails (lines 1187-1193); reuse that step, or read merge_base_commit from the compare API.
| const files = | ||
| entry.base && entry.head && entry.base.files !== entry.head.files | ||
| ? `${entry.base.files} → ${entry.head.files}` | ||
| : String(entry.head?.files ?? entry.base?.files ?? 'N/A'); | ||
| out += `| ${literal(entry.name)} | ${sizeText(entry.base?.packedBytes)} | ${sizeText(entry.head?.packedBytes)} | ${deltaText(entry.head?.packedBytes, entry.base?.packedBytes)}${entry.overBudget ? ' ⚠️' : ''} | ${sizeText(entry.base?.unpackedBytes)} | ${sizeText(entry.head?.unpackedBytes)} | ${deltaText(entry.head?.unpackedBytes, entry.base?.unpackedBytes)} | ${files} |\n`; |
There was a problem hiding this comment.
files reaches the PR comment unescaped here, and so does packedPercent at line 297. This report comes from the pull request's own CI run and is posted by the comment workflow, so render both with num() from report-text.js, as the other numeric report fields are.
| # `touches` scopes only the package-size check (a package, the | ||
| # lockfile, or the check itself); the build itself follows the | ||
| # specialized-lane outputs. | ||
| paths: '^(packages/|pnpm-lock\.yaml$|\.github/scripts/package-size\.mjs$|\.github/scripts/lib/package-size\.js$)' |
There was a problem hiding this comment.
This scope skips the measurement when only root tsconfig.json (which packages/core/tsconfig.build.json extends) or the root scripts/*.mjs that package builds run change, even though both alter the tarballs. AST-030 FR13 runs the owners' full suite for shared infrastructure. The measurement took about 15 seconds on this head, so dropping paths here is cheap.
…helper; the check also follows root build inputs - A package over its budget is flagged (job summary, PR report, a workflow warning) and fails nothing, like the component touch-only flags; the 'Size budget:' line and the enforce step are gone. - The package-size merge-base step deepens once when the 50-commit fetch holds no merge base, as size-base does. - Report counts render through num(). - tsconfig.json and scripts/ are in the check's paths scope. - size-base and the package-size lookup share lib/main-artifact.cjs.
There was a problem hiding this comment.
Changes requested: the package-size report fits the existing build owner, and the earlier escaping, merge-base deepening and shared-lookup points are fixed, but a few things remain.
- The measurement's
pathsscope (ci.yml:907) still skips a change to only rootpackage.json, whosebuildscript decides what the CLI tarball bundles, and changes to the check's own workflow steps; AST-030 FR13 runs the full suite for shared infrastructure, so also run it when the scope step reportsfull_suite. - When no merge base is found in the fetched history (about 250 main commits, roughly three days), Main kept no measurement for that commit, or the lookup fails, the note still says the base is older than 14 days (
package-size.js:244); name the real cause instead, and match the description. - The merge-base step copies
size-base's and drops its not-found warning, andsizeTextduplicates the PR comment's formatter; sharing both keeps them in step.
[Automated review]
| # `touches` scopes only the package-size check (a package, the | ||
| # lockfile, the root build inputs, or the check itself); the build | ||
| # itself follows the specialized-lane outputs. | ||
| paths: '^(packages/|pnpm-lock\.yaml$|tsconfig\.json$|scripts/|\.github/scripts/package-size\.mjs$|\.github/scripts/lib/package-size\.js$)' |
There was a problem hiding this comment.
This pattern still skips a change to only root package.json, whose build script decides what build-packages-and-storybook.mjs builds and bundles into @astryxdesign/cli, and a change to only this check's own steps in ci.yml / deploy.yml or lib/main-artifact.cjs. AST-030 FR13 runs the full suite for shared infrastructure, and the scope step already reports it as full_suite, so gating the measurement on touches == 'true' || full_suite != 'false' covers both.
| let out = '### Published Package Size\n\n'; | ||
| if (report.verdict === 'no-base') { | ||
| out += | ||
| "_Main has no kept measurement of this pull request's merge base (it is older than 14 days, or predates the measurement), so only this head's sizes are shown and no budget applies._\n\n"; |
There was a problem hiding this comment.
This note also shows when no merge base was found in the fetched history (about 250 main commits, roughly three days at the current pace), when Main's run for that commit was cancelled while queued, or when the lookup failed. Carry the cause into the report (for example a no-merge-base verdict with the baseSha) and word the note from it.
| if ! BASE_SHA=$(git merge-base "origin/$BASE_REF" HEAD); then | ||
| git fetch --deepen=200 origin "$BASE_REF:refs/remotes/origin/$BASE_REF" || true | ||
| BASE_SHA=$(git merge-base "origin/$BASE_REF" HEAD || true) | ||
| fi | ||
| echo "sha=$BASE_SHA" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
This copies size-base's merge-base step (lines 1178-1187) without its not-found warning, so a missing merge base reaches the report as an empty SHA with no message. One shared script both jobs call would keep them in step.
…a base is missing, and shares its merge-base and size helpers - The measurement also runs when the scope step reports full_suite, and for root package.json and ci.yml changes. - Without a base, the report says whether no merge base was found or Main kept (or the lookup read) no measurement, instead of blaming age. - size-base and the package-size step find the merge base with one script (merge-base.sh, with its not-found warning); the PR report's size text has one formatter (report-text.js).
There was a problem hiding this comment.
Recommended for approval: the published-package size report stays inside the existing build job, its 5% / 1 KB flag only warns, and the earlier points on the step's scope, the no-base note and the duplicated merge-base and size helpers are all fixed. One optional tidy-up: the comment above the measure step in ci.yml still says only package or lockfile changes run it, though root build inputs and shared infrastructure now do too.
[Automated review]
| # compared without building it. Only a pull request that changes a | ||
| # package or the lockfile runs it. |
There was a problem hiding this comment.
Nit (non-blocking): this still says only a package or lockfile change runs the step, but it also runs for root package.json, tsconfig.json, scripts/, the check's own files and any shared-infrastructure path (full_suite).
Maintainer impact
People who install Astryx pay for every byte a published package ships, but no pull request shows what it adds to the npm download. Test files or stray assets shipping in a package, or a new runtime dependency added for one helper, land unseen. The PR report already shows each changed component's import and CSS cost; it says nothing about the packages npm serves.
This adds that report to the build job that already builds every package, so it costs no new job, install or build.
Intended invariant
dependenciesorpeerDependencies) a published package adds or drops.lib/package-size.js.Change
package-size.mjs(withlib/package-size.js):measurerunsnpm pack --dry-run --ignore-scriptsfor every public@astryxdesign/*package, side by side;comparediffs two measurements, writes the job summary and flags an overrun.ci.ymlbuild-storybook: after its build, measures the head, finds the merge base (deepening once when the 50-commit fetch has none, assize-basedoes), finds Main's measurement of it, compares, and addspackage-size.jsonto thepr-analysisartifact. The step is scoped with the test-scope action'spaths(packages/,pnpm-lock.yaml,tsconfig.json,scripts/, the check itself); the build itself is unaffected.lib/main-artifact.cjs: one lookup for what Main keeps for a merge base, trusting only Main's own run onmainfor that exact commit.size-baseand the package-size step both use it.deploy.ymltypecheck: after itspnpm build, keepspackage-size-main-<sha>(one small JSON file) for 14 days.Evidence
main, the 11 published packages measure from 14 KB (theme-chocolate) to 9.2 MB (core, 4,545 files) download; the comparison renders the section and flags a +10% package with a warning, never a failure.build-storybooktook 18 s together (measure 15 s, lookup and compare 2 s) of a 3.5-minute job. Main'stypecheckadds the same measure step (about 15 s) once per push tomain.Scope
Testing
vitest run --project node .github/scripts: 1,558 pass.lib/package-size.test.mjs: published-package filter, a realnpm packof a fixture (honoursfiles, skips a failingprepack), the 5% / 1 KB boundary, dependency diff, Markdown, and the CLI's warning (never an error, exit 0).lib/main-artifact.test.mjs: the lookup ignores an expired artifact, a pull-request branch, another commit and a fork.>to>=at the 5% boundary; dropping--ignore-scripts; not skipping existing dependencies; passing the report for another head; rendering report strings unescaped; the lookup without its branch or expiry check; an error instead of a warning.actionlint: no new findings.Follow-ups, left out because they need extra builds: code-split import cost per component, and a check that lazy modules stay out of the startup bundle.