Skip to content

ci: report published package size and new runtime dependencies on each PR, in the build job - #9161

Merged
cixzhang merged 4 commits into
mainfrom
ci/pack-size
Oct 31, 2026
Merged

cixzhang merged 4 commits into
mainfrom
ci/pack-size

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

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

  • A pull request that changes a package, the lockfile, or this check shows, base against head, each published package's download (the gzip tarball npm fetches), unpacked size and file count, plus any runtime dependency (dependencies or peerDependencies) a published package adds or drops.
  • A published package whose download grows more than 5% and at least 1 KB is flagged ⚠️ in the job summary and the PR report, with a workflow warning. The flag is advisory, like the component touch-only budget flags: it fails nothing. No current record states a merge-blocking package budget; a blocking gate can be proposed as a spec once there is data.
  • The thresholds are starting values, kept as two constants in lib/package-size.js.

Change

  • package-size.mjs (with lib/package-size.js): measure runs npm pack --dry-run --ignore-scripts for every public @astryxdesign/* package, side by side; compare diffs two measurements, writes the job summary and flags an overrun.
  • ci.yml build-storybook: after its build, measures the head, finds the merge base (deepening once when the 50-commit fetch has none, as size-base does), finds Main's measurement of it, compares, and adds package-size.json to the pr-analysis artifact. The step is scoped with the test-scope action's paths (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 on main for that exact commit. size-base and the package-size step both use it.
  • deploy.yml typecheck: after its pnpm build, keeps package-size-main-<sha> (one small JSON file) for 14 days.
  • PR report: a "Published Package Size" section after the bundle summary, used only when it names the exact head reported. Unchanged packages fold into one line.
  • Without a kept base measurement (a merge base older than 14 days, or before this merges), the report shows head sizes only and no budget applies.

Evidence

  • Failure before the change: no PR report or check shows any package's download or unpacked size, or a new runtime dependency.
  • Success after the change: on a local build of 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.
  • Product/runtime behavior verified unchanged: CI and report only; no package source changes.
  • Cost: no new job. On this PR's first run, the new steps in build-storybook took 18 s together (measure 15 s, lookup and compare 2 s) of a 3.5-minute job. Main's typecheck adds the same measure step (about 15 s) once per push to main.

Scope

  • No intended public API, product behavior, visual direction, or policy change. The budget is an advisory flag.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • vitest run --project node .github/scripts: 1,558 pass.
  • New lib/package-size.test.mjs: published-package filter, a real npm pack of a fixture (honours files, skips a failing prepack), the 5% / 1 KB boundary, dependency diff, Markdown, and the CLI's warning (never an error, exit 0).
  • New lib/main-artifact.test.mjs: the lookup ignores an expired artifact, a pull-request branch, another commit and a fork.
  • Mutation checks, each caught by a failing test: > 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.

…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.
@vercel

vercel Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Error Error Oct 31, 2026 6:20pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 31, 2026
@astracat-bot

astracat-bot Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 31, 2026, 6:28 PM UTC

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview: the links below open this branch's latest Vercel deployment, which can trail a new push until that push's deployment is ready.

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: Accessibility did not run on this pull request; add ci:run-a11y to run it. It runs after merges to main and before each release.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
  • files and budget.packedPercent are written into the PR comment without num(), unlike every other report value (package-size.js:272-297).
  • The paths scope (ci.yml:907) skips the measurement when only root tsconfig.json or the root scripts/ 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]

Comment thread .github/workflows/ci.yml Outdated
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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +272 to +276
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`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .github/workflows/ci.yml Outdated
# `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$)'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 paths scope (ci.yml:907) still skips a change to only root package.json, whose build script 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 reports full_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, and sizeText duplicates the PR comment's formatter; sharing both keeps them in step.

[Automated review]

Comment thread .github/workflows/ci.yml Outdated
# `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$)'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .github/scripts/lib/package-size.js Outdated
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";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .github/workflows/ci.yml Outdated
Comment on lines +1050 to +1054
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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Comment thread .github/workflows/ci.yml
Comment on lines +1036 to +1037
# compared without building it. Only a pull request that changes a
# package or the lockfile runs it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

This branch had an error being deployed

1 failed deployment
Preview — 9d17c063 Deployed Oct 31, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant