Skip to content

ci: each published package commits a generated public API report, with advisory API changes for the PR report - #9241

Merged
cixzhang merged 4 commits into
mainfrom
ci/api-report
Nov 1, 2026
Merged

cixzhang merged 4 commits into
mainfrom
ci/api-report

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

Maintainers reviewing a pull request can't easily see what it does to the published API. A renamed prop, a new export, a widened type or a changed theme target only shows up if a reviewer happens to read the right declaration. Contributors get no signal either. This PR puts each published package's public surface in a committed report. CI compares the head's build with the merge base's reports and writes the advisory API changes to the pr-analysis artifact. The PR report shows them as one API changes line once its renderer follow-up lands. Nothing here fails CI or blocks a contributor.

Intended invariant

architecture:public-component-api INV24: pnpm api:report generates one committed report per published package from its built declarations and stylesheet, with a section for each entry point. The PR report lists added, changed and removed rows against the merge base, each with its signature and a usage example, and flags a stale committed report. All of this is evidence only (INV13): it fails no check.

Change

What gets reported

  • Each package a stable release publishes gets a committed api-report.md, using the release's own package rule. Today that is @astryxdesign/build, cli, core, richtext and the seven themes.
  • The report is generated from that package's build output. Each entry point in the exports map gets its own section, listing:
    • components with their props (type, required or optional, and @default where declared)
    • hooks and functions with their signatures (one row per overload)
    • classes, values and types
    • what a subpath pattern reaches, and CommonJS entries
  • At the end of each report:
    • public custom properties from the built stylesheets (--_* excluded)
    • theme targets, read through the CLI's existing theming-target list, so there is no second registry
    • public attributes: theme reflection attributes, plus the public data-astryx-* names from INV23, read from the lint rule's PUBLIC_ATTRIBUTES that enforces that list
    • reachable members tagged @internal
  • Marks: @internal, @experimental and @deprecated show on the row. Core's ./internal/* and unpublished packages are left out.

Format and the change comparison

  • One row per line, sorted, byte-stable across runs.
  • Each package gets its own TypeScript program, so one package's module augmentations never leak into another's report.
  • Inferred types longer than 200 characters (StyleX objects, palettes) are cut short and end in a short content hash, so any change still shows as a changed row.
  • scripts/api-report/changes.mjs keys rows by entry point, section, item and member. A custom property keeps its stylesheet in its key and a theme target its component, so one name in two places stays two rows. It produces added, changed and removed rows with a usage example. A package with no report at the merge base reads as "new report".

Commands

  • pnpm api:report writes every report. --package <name> writes one, and each published package also has its own api:report script.
  • --check exits 1 on a stale report, for local use only.
  • --changes --base <sha> writes api-changes.json and api-changes.md, and always exits 0.

CI

  • One step in the existing build-storybook job, just before the analysis artifact upload. It reads the dists that job already built and diffs against the reports committed at the merge base. Those are read with git show: no GitHub API calls, and the base is not built. With no merge base the step exits without comparing.
  • The step uses continue-on-error and a 2-minute timeout.
  • It adds api-changes.json to the pr-analysis artifact. Until the PR report's renderer follow-up lands, the changes live only in that artifact; the renderer escapes every string.

Changeset coverage

  • A package-root api-report.md is not in any package's tarball, but coverage treated it as shipped because the !**/… exclusion globs in files fail closed. Coverage now exempts it unless files actually packs it, so regenerating a report never needs a Changeset. Two tests cover it.

Diffs

  • .gitattributes marks the reports as generated, so their raw diffs collapse. Reviewers read the API changes line instead.

Dependencies

  • No new dependencies. It uses the TypeScript compiler API, which is already a root dev dependency, and the CLI's existing theming-target discovery. The repo has no api-extractor or typedoc to reuse.

Evidence

  • Before: no committed record of the published surface; API deltas were invisible in review.
  • After: 11 reports are committed (core 10,462 lines, cli 2,513, richtext 175, build 73, each theme about 250). pnpm api:report --check passes on this head.
  • --changes --base origin/main on this head prints one line, "new report", for each package, since main has no reports yet. On a later PR it lists rows. The fixture test covers added, changed and removed rows, a stale report, and the empty case.
  • Product and runtime behavior are unchanged: no package source changes. The only package changes are an api:report script in each published package.json and the report files, which are outside every package's files list and so are not published.

Scope

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split. The four reachable @internal members in core are recorded as baseline rows, not changed here.
  • Public text and artifacts contain no internal Meta context.

Risk

  • Critical path: the step adds a few seconds to build-storybook. Generating all 11 reports takes about 6 seconds of CPU locally. It can't fail the job: continue-on-error, a 2-minute timeout, and the script exits 0 in --changes mode.
  • Stale reports: a report that drifts from the build is flagged in the API changes (stale: true), not failed. Regenerate with pnpm build && pnpm api:report.
  • Large changes: a big refactor yields many rows. The rendered rows are capped, with an "…and N more" line.
  • Where the changes show: until the renderer follow-up lands, API changes are in the pr-analysis artifact only, not in the PR report.

CI impact

Item Change
Runner class none: an existing ubuntu-latest job (build-storybook)
Job-minutes per update about +0.1–0.3 (one step, no new job)
Wall-clock about +5–20 s on build-storybook; target ≤30 s at p90, measured on this PR's run
Runs per day unchanged: runs only where build-storybook already runs (PRs that touch packages)

Testing

  • vitest run --project node scripts/api-report: 14 tests over a fixture package. They cover:
    • every row kind, CommonJS and pattern entries
    • ./internal/*, private custom properties and unlisted attributes being left out
    • the internal and experimental marks
    • one detailed listing per declaration
    • sort order, byte-identical reruns
    • the change rows, the stale flag, the new-report and empty cases, and usage for package-level rows
    • only the packages a stable release publishes (private and canary-only left out)
  • pnpm build && pnpm api:report, then --check (clean) and --changes --base origin/main.
  • changeset-coverage.test.mjs (87 tests, including the two new ones), and changeset-coverage.mjs pr on this branch: nothing ships.
  • pnpm check:repo, the copyright check, and Prettier on the reports and scripts. Rows sit in text fences, so Prettier leaves them alone.

@vercel

vercel Bot commented Nov 1, 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 2:00am UTC

Request Review

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

astracat-bot Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 1, 2026, 2:07 AM UTC

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 9937dc6

Storybook · Sandbox · built from this PR's head

Package size:

  • @astryxdesign/build 24.5 kB packed (+22 B); no new dependencies
  • @astryxdesign/cli 3.29 MB packed (+34 B); no new dependencies
  • @astryxdesign/core 6.54 MB packed (+24 B); no new dependencies
8 more packages
  • @astryxdesign/richtext 190.5 kB packed (+20 B); no new dependencies
  • @astryxdesign/theme-butter 45.5 kB packed (+22 B); no new dependencies
  • @astryxdesign/theme-chocolate 13.5 kB packed (+26 B); no new dependencies
  • @astryxdesign/theme-gothic 32.6 kB packed (+23 B); no new dependencies
  • @astryxdesign/theme-matcha 28.0 kB packed (+20 B); no new dependencies
  • @astryxdesign/theme-neutral 35.4 kB packed (+20 B); no new dependencies
  • @astryxdesign/theme-stone 37.6 kB packed (+20 B); no new dependencies
  • @astryxdesign/theme-y2k 34.7 kB packed (+24 B); 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

@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 generator matches INV24 and the committed reports regenerate byte-identically from this head's build. However, two required checks fail and the API changes are wrong in two cases.

  • lint: Changeset coverage counts each api-report.md as shipped docs because isPackedFile fails closed on the !**/… globs in files; mark package-root reports as not shipping in scripts/release/changeset-coverage.mjs rather than adding Changesets.
  • test-ui (1/4): four fixtures under scripts/api-report/__fixtures__/repo/packages/demo/lib/ need the copyright header.
  • When merge-base.sh finds no merge base, the step falls back to the committed report and reports zero changes, so it should exit instead.
  • Stylesheet, theme-target and attribute rows get usage like import {--x} from '@astryxdesign/core', because usageFor checks section while parseReport stores those headings in entry.
  • Reuse isStableReleasePackage and the lint rule's PUBLIC_ATTRIBUTES instead of re-deriving the package and attribute lists.
  • Until the PR report renders the API changes, drop "the PR report gets its API changes" from the title and the step comment.

[Automated review]

Comment thread .github/workflows/ci.yml Outdated
Comment on lines +1171 to +1172
BASE_SHA=$(.github/scripts/merge-base.sh "$BASE_REF" 'the API changes' || true)
node scripts/api-report/cli.mjs --changes ${BASE_SHA:+--base "$BASE_SHA"}

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 merge-base.sh finds no merge base it prints nothing, but this still runs --changes without --base. cli.mjs:151 then compares against the head's own committed report, so the output reads as zero API changes (baseline: false, 0 rows, empty api-changes.md). INV24 asks for changes against the merge base's report, so exit here when BASE_SHA is empty (for example [ -n "$BASE_SHA" ] || exit 0).

Comment thread scripts/api-report/changes.mjs Outdated
export function usageFor(pkg, row) {
const spec = row.entry.startsWith('./') ? `${pkg}${row.entry.slice(1)}` : pkg;
const [kind, name = row.item] = row.item.split(' ');
if (row.section === 'Stylesheets') return `.my-scope { ${name}: …; }`;

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.

parseReport (line 45) puts a package-level heading such as Stylesheets in entry and leaves section empty, so this branch and the next three never match. An added custom property currently gets import {--x} from '@astryxdesign/core'. Check row.entry here, and add a tail-row case to the test.

* @param {string} repoRoot
* @returns {Array<{name: string, dir: string}>}
*/
export function publishedPackages(repoRoot) {

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 published-package discovery that .github/scripts/lib/package-size.js (publishedPackages) and scripts/release/active-release.mjs (isStableReleasePackage) already own, with a different rule: canary-only packages and the scope are ignored here. Filtering with isStableReleasePackage keeps the report set equal to what release publishes.

Comment thread scripts/api-report/generate.mjs Outdated
* @param {string} repoRoot
* @returns {string[]}
*/
export function readPublicAttributes(repoRoot) {

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.

internal/eslint-plugin-astryx/no-raw-private-attribute.js already exports PUBLIC_ATTRIBUTES, the list the lint enforces. Scraping the record's prose returns [] as soon as that sentence is reworded, and the attribute rows disappear without an error.

…c attribute list; exempt package-root reports from Changeset coverage; skip the step with no merge base
@cixzhang cixzhang changed the title ci: each published package commits a generated public API report, and the PR report gets its API changes ci: each published package commits a generated public API report, with advisory API changes for the PR report Nov 1, 2026

@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 earlier findings are fixed and all 11 reports regenerate byte for byte from this head's build, but the API changes still miss some changes to core.

  • parseReport keys a row by its first two words (scripts/api-report/changes.mjs:83-86), so 40 of core's rows collide (36 custom properties declared in both ./astryx.css and ./tailwind-theme.css, and 4 shared theme targets) and removing --color-accent from ./astryx.css reports nothing; keep the stylesheet or component in the key and add a fixture for it.
  • The description's Maintainer impact and Risk sections still say the PR report shows the API changes; reword them to say CI writes them to the pr-analysis artifact until the renderer follow-up lands.

[Automated review]

Comment thread scripts/api-report/changes.mjs Outdated

function itemName(line) {
if (/^[\w$]+ \(/.test(line)) return line.split(' ')[0]; // `Name (./entry)` in an also-exported list
const m = line.match(/^(\w+) ([^\s(:<=]+)/);

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 key keeps only the first two words, so var --color-accent (./astryx.css) and var --color-accent (./tailwind-theme.css) (36 such names in core) and target checkbox-indicator (CheckboxInput) / (Indicator) (4 shared targets) map to one row, and the later one overwrites the earlier at line 62. Removing --color-accent from ./astryx.css while ./tailwind-theme.css keeps it then yields no added, changed or removed row, which INV24 requires. Keeping the parenthesised part for var and target rows (or refusing a duplicate key) fixes it; a fixture with one custom property in two stylesheets would cover it.

@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 recommended: the API changes now keep a custom property's stylesheet and a theme target's component in the row key, so a removal from core's ./astryx.css shows up, and all 11 reports regenerate byte for byte from this head's build. Two small follow-ups, neither blocking:

  • The "Reachable members tagged internal" index lists exports only (4 in core) while 17 rows carry @internal; add the member rows or title it "Exports tagged internal".
  • Once this lands, the INV24 known-gap note in docs/architecture/public-component-api.md is out of date and can name only the PR-report rendering that remains.

[Automated review]

}
seen.set(identity, e.subpath);
const m = marks(decl, name);
if (m.includes('@internal')) internal.push(`${name} via ${e.subpath}`);

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.

Only top-level exports reach the "Reachable members tagged internal" index, so core's lists 4 while 17 rows carry @internal (for example BaseTypeahead's prop __queryEntries). Not blocking, since each row carries the mark: either add member rows here or title the section "Exports tagged internal".

@cixzhang
cixzhang merged commit 13412a4 into main Nov 1, 2026
53 checks passed
@github-actions
github-actions Bot deleted the ci/api-report branch November 1, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — 9937dc6e 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