Skip to content

ci: drop the size-base job; Main keeps every component's sizes and pull requests read the merge base's record - #9164

Merged
cixzhang merged 11 commits into
mainfrom
ci/size-base-from-main
Nov 1, 2026
Merged

cixzhang merged 11 commits into
mainfrom
ci/size-base-from-main

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

Every pull request that changes a component runs a separate size-base job. It checks out the merge base, installs its dependencies, downloads (or builds) its packages and measures them, so the PR report can show Before and Delta. Over the last 20 pull-request runs it ran 39 s on average (up to 105 s) on its own runner, plus job start-up, on every push. Main already builds every package once per commit, so this measures the same base again for each PR.

Intended invariant

  • When Main kept a record of the merge base, the PR report's Component Size, Modified Components (Before) and Bundle Size Summary (before) figures are unchanged: they come from that record, measured from Main's own build of that commit.
  • Which components are sized is unchanged: a component whose own folder changed, or whose bundle reaches a changed module, at head or at the merge base (the record keeps each component's reached source modules).
  • A pull request builds the merge base only when Main kept no record of it (below); otherwise no pull-request job installs or builds it.

Change

  • analyze-pr.js --main-record: records every public component's import and CSS gzip size, the source modules its bundle reaches, each component folder's entry stats, and every component package's bundle stats (about 140 KB of JSON).
  • analyze-pr.js --base-record <file>: reads that record instead of measuring a built merge-base checkout. --base-root and --base-only are removed; nothing else used them.
  • deploy.yml typecheck: keeps component-size-main-<sha> for 14 days in place of dists-main-<sha> (whole package builds, which only size-base read).
  • ci.yml: size-base is removed. build-storybook finds the merge base once (merge-base.sh), looks up both of Main's records for it (only from Main's own run on main for that commit, through main-artifact.cjs), and passes the component record to the analysis it already runs. The package-size steps share that lookup.
  • Without a record, for example when a later push to main replaced Main's run for that commit (about 1 in 5 recent main commits), or when the record expired: build-storybook builds the merge base itself, so every changed component keeps a before size (AST-080 FR8). The record lookup now runs before the Storybook build, and the base builds in the background beside it. It builds core and its build tooling, plus any other component package the PR changes, as size-base did, then records it with this head's analyzer. A wait before the analysis collects it, and its notice says how long the job waited. If the build fails or times out (10 min), Before and Delta stay empty, with a warning. Measured on this PR's own run, which had no record because main keeps none until this lands: the base was ready before Storybook finished (a 0 s wait). Contention made the Storybook build step 2 min 36 s, against 1 min 27 s to 2 min 14 s in three recent runs, and the job 3 min 51 s against 2 min 19 s to 3 min 30 s. So a PR without a record pays roughly +0.4 to +1.5 runner-minutes in this one job, and PRs with a record pay nothing.
  • analyze-pr.js: one targeting rule (affectedBy) decides the sized components both in a built head (sizeTargets) and from the merge base's record (recordTargets). Main's record and the head share one reach map (componentReach), so base and head targeting cannot drift apart.
  • deploy.yml measures and uploads the package size once. The merge had left the step twice, and a second upload of one name would fail the job. A new contract (workflow-artifact-names.test.mjs) fails any job that uploads one artifact name twice.
  • The PR Comment workflow still tries to download pr-size-base. Nothing produces it now, so that step quietly finds nothing; it goes in the follow-up PR that redesigns the report.

Evidence

  • Failure before the change: each component PR spends a second job (39 s average, 105 s worst case over 20 runs) measuring a merge base that Main has already built.
  • Success after the change: on a local build of main, --main-record writes 232 components, 707 reached modules and 5 package bundles. The converted tests read Before figures, reach-only components and a renamed defining module from the record.
  • Product/runtime behavior verified unchanged: CI and report only; no package source changes.
  • Minutes: measured on this PR's own run (see the comment below once CI finishes).

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • 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.
  • analyze-pr.test.mjs: the three merge-base tests now build the base, write its record with --main-record, and analyze the head with --base-record: reach decided only in the base build, a renamed defining module, entry and bundle stats, a family folder's new member (no base figure), and a missing record (no Before, head still sized).
  • ci-tooling-routing.test.mjs: no size-base job; Main keeps the component record and no longer the package builds; build-storybook trusts only Main's run for the merge-base commit and downloads the record before the analysis reads it.
  • actionlint: no new findings.

…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.
…ll requests read the merge base's record

Main's typecheck job records every public component's import and CSS
size, the source modules its bundle reaches, its entry stats and every
package's bundle stats (analyze-pr.js --main-record), and keeps it for
14 days in place of the whole package builds. build-storybook reads the
merge base's record (--base-record), so no pull-request job installs or
builds the merge base.
@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 Ready Ready Preview Nov 1, 2026 12:27am 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) Nov 1, 2026, 12:37 AM UTC

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

Requesting changes: reading the merge base's sizes from Main's per-commit record works where a record is found, but two gaps need fixing first.

  • The new "Find the merge base" step in ci.yml runs before anything deepens the depth-50 clone, so a PR 50 or more main commits behind finds no record and loses Before/Delta and the package-size budget; please restore the git fetch --deepen=200 fallback the removed size-base job had, with a routing test.
  • The description says the Before figures are unchanged, but the removed build fallback also covered merge bases whose Main run was superseded by a later push (several recent main commits have no kept Main build) and stacked PRs, so please name those cases in the description or build the base only when no record exists.

[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' && github.event_name == 'pull_request'
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 runs on the depth-50 clone before anything deepens it (analyze-pr.js only deepens later, inside the analysis), so a PR 50 or more main commits behind gets an empty SHA, no record, and no package-size base. The removed size-base step deepened first:

if ! SHA=$(git merge-base "origin/$BASE_REF" HEAD); then
  git fetch --deepen=200 origin "$BASE_REF:refs/remotes/origin/$BASE_REF" || true
  SHA=$(git merge-base "origin/$BASE_REF" HEAD || true)
fi
echo "sha=$SHA" >> "$GITHUB_OUTPUT"

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

Requesting changes: reading the merge base's sizes from Main's per-commit record works where a record exists, and the earlier depth-50 lookup gap is fixed, but three points remain.

  • When Main kept no record for the merge base (a main push whose Main run was superseded, or any pull request into release/**), the report now shows no Before or Delta where size-base used to build the base, so please build the base only in that case.
  • The description says the Before figures are unchanged, so please make that true or name those cases.
  • recordTargets and writeMainRecord repeat sizeTargets' targeting rule, so please share one helper so base and head targeting cannot drift.

[Automated review]

Comment thread .github/workflows/ci.yml Outdated
const name = `${prefix}-${process.env.BASE_SHA}`;
const runId = await mainArtifactRunId({github, ...context.repo, name, sha: process.env.BASE_SHA});
core.setOutput(output, runId ?? '');
core.info(runId ? `Using ${name} from run ${runId}.` : `No ${name}; its Before and Delta stay empty.`);

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.

When this finds no record (Main kept none for 7 of its last 39 commits, because a later push supersedes a pending run, and a release/** merge base never has one), the analysis runs without --base-record, and Before and Delta go N/A. The removed size-base job built the base in that case. Could this build and measure the merge base only when no record is found?

// The components a change can affect in the merge base's build, from its
// record: as sizeTargets decides in a built tree, a component whose own folder
// or file changed, or whose bundle reached a changed module of any package.
function recordTargets(record, changedFiles) {

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 repeats sizeTargets' rule, the own-folder test and the reach test, and writeMainRecord repeats its mapping from bundle input to src module. If one helper decided a target and one mapped inputs, all three could call them, and base and head targeting could not drift apart.

@cixzhang
cixzhang changed the base branch from ci/pack-size to main October 31, 2026 18:35
@cixzhang
cixzhang marked this pull request as ready for review October 31, 2026 18:44

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

Requesting changes: merging main left Main's package-size measurement and upload in the typecheck job twice, so once this lands every push to main would fail at the second package-size-main-<sha> upload, and the earlier points are still open.

  • Delete the second copy of the package-size steps in deploy.yml (lines 158-168).
  • When Main kept no record for the merge base (a Main run a later push replaced, or a merge base only on a release/** branch), Before and Delta now show N/A where size-base built the base, which the description's "unchanged" claim leaves out; please build the base only in that case, or name those cases.
  • recordTargets and writeMainRecord repeat sizeTargets' targeting rule, so one shared helper would keep base and head targeting from drifting apart.

[Automated review]

Comment thread .github/workflows/deploy.yml Outdated
Comment on lines +146 to +155
# A pull request compares its published package sizes with its merge
# base's from this measurement (ci.yml build-storybook).
- name: Measure published package size
run: node .github/scripts/package-size.mjs measure --output package-size.json

- name: Keep this commit's package size for PR size reports
uses: actions/upload-artifact@v7
with:
name: package-size-main-${{ needs.main-commit.outputs.sha }}
path: package-size.json

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.

After the merge of main, this block and the existing one at lines 158-168 both measure and upload package-size-main-${{ needs.main-commit.outputs.sha }} in the same job. upload-artifact refuses a second artifact with the same name in one run unless overwrite: true, so Main's typecheck would fail on every push to main and skip the export and type checks after it. Deleting lines 158-168 keeps one copy.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · f6bb592

Storybook · Sandbox · built from this PR's head

Package size: no published package changed; no new dependencies.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

…rgeting rule and reach map for the head and the merge base's record; name the cases with no base record

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

Reading the merge base's sizes from Main's per-commit record works: where a record exists, the Before figures, sized components and audit dependents match what size-base produced, and the duplicated package-size upload, the description's claim and the copied targeting rule from the last review are fixed. Approval now waits on one owner decision: architecture:component-style-authoring INV6 and spec:AST-080 FR8 require a base-against-head size for every changed component, and this change intentionally shows N/A when Main kept no record for the merge base, where size-base used to build it. An engineering owner settles that on this pull request, either by updating INV6 and FR8 on main to allow the gap and commenting /approve-spec <full head SHA>, or by asking for the merge base to be built only when no record is found; the author may decide as an engineering owner.

[Automated review]

Comment thread .github/workflows/ci.yml
Comment on lines +1111 to +1114
BASE_RECORD=()
if [ -f .component-size-base/component-size.json ]; then
BASE_RECORD=(--base-record .component-size-base/component-size.json)
fi

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.

When no record was downloaded, the analysis runs without a base, so Before and Delta show N/A; the removed size-base job built the merge base in that case. architecture:component-style-authoring INV6 and spec:AST-080 FR8 require a base-against-head figure for every changed component, so this needs an engineering owner's decision: amend those claims on main, or build and measure the merge base only when no record is found.

…he base beside the Storybook build, so every changed component keeps a before size (AST-080 FR8)

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

Requesting changes: building the merge base inside build-storybook when Main kept no record closes the earlier Before/Delta gap, and CI on this commit took that path successfully, but some wording still says the base is never built. Please reword the description's invariant "No pull-request job installs or builds the merge base", the component lookup's log line "its Before and Delta stay empty" (ci.yml:1013), and the routing test's "never building the base" title and comment (ci-tooling-routing.test.mjs:239 and :135) so they say the base is built only when Main kept no record.

[Automated review]

Comment thread .github/workflows/ci.yml Outdated
const name = `${prefix}-${process.env.BASE_SHA}`;
const runId = await mainArtifactRunId({github, ...context.repo, name, sha: process.env.BASE_SHA});
core.setOutput(output, runId ?? '');
core.info(runId ? `Using ${name} from run ${runId}.` : `No ${name}; its Before and Delta stay empty.`);

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.

For component-size-main, the next step builds the merge base when this finds nothing, so "its Before and Delta stay empty" no longer holds; CI on this commit printed it one line before the base build started. Something like No ${name}; building the merge base instead. for the component record keeps the log accurate.

});

it("measures the merge base from main's kept build, building it only without one", () => {
it("reads the merge base's sizes from main's kept records, never building the base", () => {

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 test now asserts the fallback build, so "never building the base" (and the comment at line 135, "No pull-request job builds the merge base") no longer matches; for example "reads the merge base's sizes from main's kept records, building the base only without one".

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

Requesting changes: reading the merge base's sizes from Main's record, and building the base inside build-storybook when there is none, works on this head's own CI, and the earlier wording is fixed. One line remains: the record lookup's miss message (.github/workflows/ci.yml:1013) now says the merge base is built for the package-size-main record too, which the fallback never builds, so keep "sizes are shown without a budget" for that record and the new message for the component record only.

[Automated review]

Comment thread .github/workflows/ci.yml Outdated
const name = `${prefix}-${process.env.BASE_SHA}`;
const runId = await mainArtifactRunId({github, ...context.repo, name, sha: process.env.BASE_SHA});
core.setOutput(output, runId ?? '');
core.info(runId ? `Using ${name} from run ${runId}.` : `No ${name}; the merge base is built here instead.`);

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 loop also runs for package-size-main, but the fallback below builds only the component record (component_run_id == '', line 1033), and the package comparison then reports Main's measurement as not found. Choosing the message by record keeps the log accurate:

const missing = output === 'component_run_id'
  ? 'the merge base is built here instead'
  : 'sizes are shown without a budget';
core.info(runId ? `Using ${name} from run ${runId}.` : `No ${name}; ${missing}.`);

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

Requesting changes: the per-record miss message is fixed, and reading the merge base's sizes from Main's record, with an in-job build when there is none, works on this head's CI. One gap remains: when the lookup finds Main's record but the download step fails, nothing builds the merge base, so Before and Delta show N/A where the removed size-base job built it (it keyed on steps.download.outcome != 'success'). Giving the download step an id and starting the fallback on that step's outcome (.github/workflows/ci.yml:1036) covers both misses, and the routing test's start.if assertion moves with it.

[Automated review]

Comment thread .github/workflows/ci.yml Outdated
# in the background; the wait before the analysis collects it.
- name: Start building the merge base without a record
id: base-build
if: steps.scope.outputs.docsite_only != 'true' && steps.scope.outputs.spec_only != 'true' && steps.scope.outputs.tooling_only != 'true' && steps.merge-base.outputs.sha != '' && steps.size-records.outputs.component_run_id == ''

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 starts the build only when the lookup found no run. If the lookup finds Main's record but the download step above fails (it has continue-on-error: true), there is no record and no fallback, so Before and Delta go N/A; the removed size-base job built the base on any download miss (steps.download.outcome != 'success'). Giving the download step an id and keying on its outcome covers both cases, since the download is skipped when the lookup finds nothing:

if: ... && steps.merge-base.outputs.sha != '' && steps.component-size-download.outcome != 'success'

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

Recommending approval: reading the merge base's sizes from Main's per-commit record, with the merge base built inside build-storybook whenever that record is not downloaded, keeps base-against-head sizes on every path, and this head's CI ran the no-record path successfully. The last open point, a found record whose download fails, is fixed by starting the fallback on the download step's outcome. The required test check failed only in an unrelated CLI watch test (build-theme.watch.test.mjs) and needs a re-run before merge.

[Automated review]

@cixzhang
cixzhang merged commit f0039ff into main Nov 1, 2026
86 of 88 checks passed
cixzhang added a commit that referenced this pull request Nov 1, 2026
@github-actions
github-actions Bot deleted the ci/size-base-from-main branch November 1, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — f6bb5927 Deployed Nov 1, 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