Skip to content

Add PR check reporting npm package size changes - #4918

Draft
timotheeguerin wants to merge 1 commit into
mainfrom
add-package-size-pr-check
Draft

Add PR check reporting npm package size changes#4918
timotheeguerin wants to merge 1 commit into
mainfrom
add-package-size-pr-check

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

Summary

Adds a PR check that reports how a change affects the published npm package size of the workspace libraries and posts the result as a sticky comment. Purely informational — it never fails the check.

Since these TypeSpec libraries are not bundled (they build with tsc and publish dist/**), "size" here is the npm tarball that npm pack produces — both packed (gzipped .tgz) and unpacked sizes.

How it works

Two workflows, following the secure two-stage pattern already used by core/.github/workflows/commenter.yml (so it works for fork PRs without exposing a write token to untrusted code):

  • package-size.yml (pull_request, read-only, scoped via paths:) — builds + measures the PR head, checks out the base commit, builds + measures it, diffs the two, and uploads the rendered comment as an artifact.
  • package-size-comment.yml (workflow_run, pull-requests: write) — downloads the artifact and posts/updates a single sticky comment (keyed by a hidden marker).

New scripts under eng/scripts/bundle-size/ (run with tsx):

  • measure.ts — enumerates publishable packages via listPackages() (skips private/unnamed), runs npm pack --dry-run --json --ignore-scripts per package.
  • compare.ts — renders a markdown table of packed/unpacked deltas (%), flags 🆕 added / 🗑️ removed packages, and collapses unchanged packages into a <details> block.
  • utils.ts — byte/delta/percent formatting helpers.

Example comment

📦 Package size report

1 package changed size compared to the base branch.

Package Packed (base → head) Δ Packed Unpacked (base → head) Δ Unpacked
`@azure-tools/typespec-azure-core` 126.32 KB → 131.52 KB +5.20 KB (+4.1%) 685.38 KB → 697.10 KB +11.72 KB (+1.7%)

Notes

  • Measures all publishable workspace packages (includes core/packages/*); in a normal Azure PR those stay in the collapsed "unchanged" section.
  • Cost: two full builds per qualifying PR — mitigated by the paths: filter and a dedicated non-required workflow.

Validation

  • Scripts run locally (measured 51 packages; test fixtures skipped gracefully); simulated grow/shrink/add/remove diff renders correctly.
  • tsc -p tsconfig.eng.json passes, prettier clean, actionlint passes on both workflows, chronus verify confirms no changelog entry is required (eng/CI-only change).

Adds a PR workflow that measures the published npm tarball size (packed and
unpacked) of every publishable workspace package at the PR head and base, then
posts a sticky comment with the per-package size delta. Purely informational;
never fails the check.
@azure-sdk-automation

Copy link
Copy Markdown
Contributor

No changes needing a change description found.

@azure-sdk-automation

Copy link
Copy Markdown
Contributor

You can try these changes here

🛝 Playground 🌐 Website

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant