From d7e25ee5b13651f5cbee326620dece4a24705265 Mon Sep 17 00:00:00 2001 From: Effect Bot Date: Thu, 26 Nov 2026 11:44:12 +0000 Subject: [PATCH 1/4] Report bundle size in a comment on pull requests --- .github/workflows/bundle-size-comment.yml | 55 +++++++++++++++++++++ .github/workflows/check.yml | 20 +++++++- packages/ui/benchmark/bundle-size/README.md | 3 +- packages/ui/benchmark/bundle-size/run.mjs | 6 ++- 4 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/bundle-size-comment.yml diff --git a/.github/workflows/bundle-size-comment.yml b/.github/workflows/bundle-size-comment.yml new file mode 100644 index 000000000..eb94d12f9 --- /dev/null +++ b/.github/workflows/bundle-size-comment.yml @@ -0,0 +1,55 @@ +name: Bundle size comment +on: + workflow_run: + workflows: [Check] + types: [completed] + +# Runs for one PR branch are serialized so they cannot both create a comment. +concurrency: + group: ${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }} + +permissions: {} + +jobs: + comment: + name: Comment + if: github.event.workflow_run.event == 'pull_request' + runs-on: ubuntu-latest + permissions: + actions: read + pull-requests: write + timeout-minutes: 5 + steps: + # The report comes from PR code: never check out or run it, only post it as text. + - name: Create or update comment + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RUN_ID: ${{ github.event.workflow_run.id }} + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + run: | + artifacts=$(gh api "repos/$GH_REPO/actions/runs/$RUN_ID/artifacts" --jq '[.artifacts[] | select(.name == "bundle-size")] | length') + if [[ "$artifacts" == 0 ]]; then + echo "Run $RUN_ID has no bundle size report." + exit 0 + fi + gh run download "$RUN_ID" --name bundle-size --dir report + pr=$( body.md + ids=$(gh api --paginate "repos/$GH_REPO/issues/$pr/comments" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id") + if [[ -n "$ids" ]]; then + gh api --method PATCH "repos/$GH_REPO/issues/comments/${ids%%$'\n'*}" -F body=@body.md --silent + else + gh api "repos/$GH_REPO/issues/$pr/comments" -F body=@body.md --silent + fi diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 0a6fa21db..77c35a639 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -78,11 +78,27 @@ jobs: - name: Report bundle size run: | base="$RUNNER_TEMP/base-size.json" + report="$RUNNER_TEMP/bundle-size/report.md" + mkdir -p "$(dirname "$report")" if [[ -f "$base" ]]; then - pnpm bundle-size --base "$base" + pnpm bundle-size --base "$base" --markdown "$report" else - pnpm bundle-size + pnpm bundle-size --markdown "$report" fi + # The Bundle size comment workflow posts this report, as fork PRs get a read-only token here. + - name: Save PR number + if: github.event_name == 'pull_request' + run: echo "$PR" > "$RUNNER_TEMP/bundle-size/pr" + env: + PR: ${{ github.event.pull_request.number }} + - name: Upload report + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: bundle-size + path: ${{ runner.temp }}/bundle-size + retention-days: 7 + if-no-files-found: error test: name: Test (${{ matrix.runtime }}) diff --git a/packages/ui/benchmark/bundle-size/README.md b/packages/ui/benchmark/bundle-size/README.md index 16f7af1ef..8dc8ccb0f 100644 --- a/packages/ui/benchmark/bundle-size/README.md +++ b/packages/ui/benchmark/bundle-size/README.md @@ -3,7 +3,7 @@ Bundle sizes of small @effect/ui clients, bundled with Vite against the packed @effect/ui and @effect/ui-kit as an external consumer would. Run from the repository root, after `pnpm build`: ```sh -pnpm bundle-size [--app ]... [--development] [--json ] [--base ] +pnpm bundle-size [--app ]... [--development] [--json ] [--base ] [--markdown ] ``` Apps: `counter` (`counter.ts`), `features` (`features.ts`: a Layer, a slot, a failure fallback and the message log) and `routing` (`examples/routing`). Every app is measured unless `--app` picks some. Each bundle runs in happy-dom before it counts. Added gzip bytes are an app's total minus a separately bundled effect-only client. @@ -13,5 +13,6 @@ Apps: `counter` (`counter.ts`), `features` (`features.ts`: a Layer, a slot, a fa | `--development` | bundle without the `production` export condition, keeping development-only checks | | `--json` | write the result to a file | | `--base` | add deltas against an earlier `--json` file; an older single-app file compares the counter only | +| `--markdown` | write the table to a file | The table is also appended to `$GITHUB_STEP_SUMMARY` when that is set. diff --git a/packages/ui/benchmark/bundle-size/run.mjs b/packages/ui/benchmark/bundle-size/run.mjs index f01b905d3..1e523bd2f 100644 --- a/packages/ui/benchmark/bundle-size/run.mjs +++ b/packages/ui/benchmark/bundle-size/run.mjs @@ -8,12 +8,13 @@ import { parseArgs } from "node:util" import { gzipSync } from "node:zlib" import { build, version as vite } from "vite" -const { values: { app: only, base, development, json } } = parseArgs({ +const { values: { app: only, base, development, json, markdown } } = parseArgs({ options: { app: { type: "string", multiple: true }, development: { type: "boolean", default: false }, base: { type: "string" }, - json: { type: "string" } + json: { type: "string" }, + markdown: { type: "string" } } }) process.env.NODE_ENV = development ? "development" : "production" @@ -337,6 +338,7 @@ const report = [ ].join("\n") console.log(report) if (json) fs.writeFileSync(json, JSON.stringify(result) + "\n") +if (markdown) fs.writeFileSync(markdown, report) if (process.env.GITHUB_STEP_SUMMARY) { fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, report) } From 59119281104a6a14303dbdf902d51725ef3a042d Mon Sep 17 00:00:00 2001 From: Effect Bot Date: Thu, 26 Nov 2026 12:31:23 +0000 Subject: [PATCH 2/4] Simplify bundle size report steps --- .github/workflows/bundle-size-comment.yml | 8 ++++---- .github/workflows/check.yml | 18 +++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/.github/workflows/bundle-size-comment.yml b/.github/workflows/bundle-size-comment.yml index eb94d12f9..2ee5801ab 100644 --- a/.github/workflows/bundle-size-comment.yml +++ b/.github/workflows/bundle-size-comment.yml @@ -28,7 +28,7 @@ jobs: RUN_ID: ${{ github.event.workflow_run.id }} HEAD_SHA: ${{ github.event.workflow_run.head_sha }} run: | - artifacts=$(gh api "repos/$GH_REPO/actions/runs/$RUN_ID/artifacts" --jq '[.artifacts[] | select(.name == "bundle-size")] | length') + artifacts=$(gh api "repos/$GH_REPO/actions/runs/$RUN_ID/artifacts?name=bundle-size" --jq .total_count) if [[ "$artifacts" == 0 ]]; then echo "Run $RUN_ID has no bundle size report." exit 0 @@ -47,9 +47,9 @@ jobs: fi marker="" { echo "$marker"; cat report/report.md; } > body.md - ids=$(gh api --paginate "repos/$GH_REPO/issues/$pr/comments" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id") - if [[ -n "$ids" ]]; then - gh api --method PATCH "repos/$GH_REPO/issues/comments/${ids%%$'\n'*}" -F body=@body.md --silent + id=$(gh api --paginate "repos/$GH_REPO/issues/$pr/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id" | head -n 1) + if [[ -n "$id" ]]; then + gh api --method PATCH "repos/$GH_REPO/issues/comments/$id" -F body=@body.md --silent else gh api "repos/$GH_REPO/issues/$pr/comments" -F body=@body.md --silent fi diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 77c35a639..07dffe6de 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -75,20 +75,16 @@ jobs: pnpm install pnpm build env -u GITHUB_STEP_SUMMARY pnpm bundle-size --json "$RUNNER_TEMP/base-size.json" + # The Bundle size comment workflow posts this report, as fork PRs get a read-only token here. - name: Report bundle size run: | base="$RUNNER_TEMP/base-size.json" - report="$RUNNER_TEMP/bundle-size/report.md" - mkdir -p "$(dirname "$report")" - if [[ -f "$base" ]]; then - pnpm bundle-size --base "$base" --markdown "$report" - else - pnpm bundle-size --markdown "$report" - fi - # The Bundle size comment workflow posts this report, as fork PRs get a read-only token here. - - name: Save PR number - if: github.event_name == 'pull_request' - run: echo "$PR" > "$RUNNER_TEMP/bundle-size/pr" + dir="$RUNNER_TEMP/bundle-size" + mkdir -p "$dir" + args=(--markdown "$dir/report.md") + if [[ -f "$base" ]]; then args+=(--base "$base"); fi + pnpm bundle-size "${args[@]}" + if [[ -n "$PR" ]]; then echo "$PR" > "$dir/pr"; fi env: PR: ${{ github.event.pull_request.number }} - name: Upload report From e73047102c87be2e4d33faa27c8ac17e1da47f1b Mon Sep 17 00:00:00 2001 From: Effect Bot Date: Thu, 26 Nov 2026 12:35:14 +0000 Subject: [PATCH 3/4] Render the bundle size comment from measured numbers --- .github/workflows/bundle-size-comment.yml | 60 +++++++++++++++------ .github/workflows/check.yml | 15 +++--- packages/ui/benchmark/bundle-size/README.md | 3 +- packages/ui/benchmark/bundle-size/run.mjs | 6 +-- 4 files changed, 53 insertions(+), 31 deletions(-) diff --git a/.github/workflows/bundle-size-comment.yml b/.github/workflows/bundle-size-comment.yml index 2ee5801ab..2bc8fb1a1 100644 --- a/.github/workflows/bundle-size-comment.yml +++ b/.github/workflows/bundle-size-comment.yml @@ -20,36 +20,64 @@ jobs: pull-requests: write timeout-minutes: 5 steps: - # The report comes from PR code: never check out or run it, only post it as text. + # The artifact comes from PR code. Never check out or run it: only numbers from it reach the comment. - name: Create or update comment env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} RUN_ID: ${{ github.event.workflow_run.id }} + RUN_URL: ${{ github.event.workflow_run.html_url }} HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }} + HEAD_OWNER: ${{ github.event.workflow_run.head_repository.owner.login }} + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} + MARKER: "" run: | artifacts=$(gh api "repos/$GH_REPO/actions/runs/$RUN_ID/artifacts?name=bundle-size" --jq .total_count) if [[ "$artifacts" == 0 ]]; then echo "Run $RUN_ID has no bundle size report." exit 0 fi - gh run download "$RUN_ID" --name bundle-size --dir report - pr=$( body.md - id=$(gh api --paginate "repos/$GH_REPO/issues/$pr/comments?per_page=100" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | .id" | head -n 1) - if [[ -n "$id" ]]; then - gh api --method PATCH "repos/$GH_REPO/issues/comments/$id" -F body=@body.md --silent + gh run download "$RUN_ID" --name bundle-size --dir sizes + [[ -f sizes/base.json ]] || echo null > sizes/base.json + jq -r --slurpfile base sizes/base.json ' + def size: if type == "number" and . == floor and . >= 0 and . < 1e9 then . else error("invalid size") end; + def apps: [.apps[] | { + name: (.name | if IN("counter", "features", "routing") then . else error("unknown app") end), + chunks: (.chunks | size), raw: (.raw | size), gzip: (.gzip | size) + }]; + def signed: if . > 0 then "+\(.)" else tostring end; + def row: "| " + (map(tostring) | join(" | ")) + " |"; + (.baselineGzip | size) as $baseline + | apps as $head + | ($base[0] | if . == null then null else (try (apps | map({key: .name, value: .}) | from_entries) catch {}) end) as $before + | (["App", "Chunks", "Raw bytes", "Gzip bytes", "Added gzip B"] + + if $before then ["Δ raw bytes", "Δ gzip bytes"] else [] end) as $headers + | env.MARKER, + "### Bundle size", + "", + "Production build, gzip level 9 per chunk. Effect-only client: \($baseline) B gzip. [Full report](\(env.RUN_URL))", + "", + ($headers | row), + ($headers | map("---") | row), + ($head[] | . as $app + | [.name, .chunks, .raw, .gzip, .gzip - $baseline] + + if $before == null then [] + elif $before[.name] then [($app.raw - $before[.name].raw | signed), ($app.gzip - $before[.name].gzip | signed)] + else ["n/a", "n/a"] end + | row) + ' sizes/head.json > body.md + ids=$(gh api --paginate "repos/$GH_REPO/issues/$pr/comments?per_page=100" \ + --jq '.[] | select(.user.login == "github-actions[bot]" and (.body | startswith(env.MARKER))) | .id') + if [[ -n "$ids" ]]; then + gh api --method PATCH "repos/$GH_REPO/issues/comments/${ids%%$'\n'*}" -F body=@body.md --silent else gh api "repos/$GH_REPO/issues/$pr/comments" -F body=@body.md --silent fi diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 07dffe6de..e66fdae57 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -70,24 +70,21 @@ jobs: # A base that cannot be measured leaves no file, and the report shows absolute sizes only. continue-on-error: true run: | + mkdir -p "$RUNNER_TEMP/bundle-size" git worktree add --detach "$RUNNER_TEMP/bundle-base" HEAD^1 cd "$RUNNER_TEMP/bundle-base" pnpm install pnpm build - env -u GITHUB_STEP_SUMMARY pnpm bundle-size --json "$RUNNER_TEMP/base-size.json" - # The Bundle size comment workflow posts this report, as fork PRs get a read-only token here. + env -u GITHUB_STEP_SUMMARY pnpm bundle-size --json "$RUNNER_TEMP/bundle-size/base.json" - name: Report bundle size run: | - base="$RUNNER_TEMP/base-size.json" dir="$RUNNER_TEMP/bundle-size" mkdir -p "$dir" - args=(--markdown "$dir/report.md") - if [[ -f "$base" ]]; then args+=(--base "$base"); fi + args=(--json "$dir/head.json") + if [[ -f "$dir/base.json" ]]; then args+=(--base "$dir/base.json"); fi pnpm bundle-size "${args[@]}" - if [[ -n "$PR" ]]; then echo "$PR" > "$dir/pr"; fi - env: - PR: ${{ github.event.pull_request.number }} - - name: Upload report + # Fork PRs get a read-only token here, so the Bundle size comment workflow posts the sizes. + - name: Upload sizes if: github.event_name == 'pull_request' uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: diff --git a/packages/ui/benchmark/bundle-size/README.md b/packages/ui/benchmark/bundle-size/README.md index 8dc8ccb0f..16f7af1ef 100644 --- a/packages/ui/benchmark/bundle-size/README.md +++ b/packages/ui/benchmark/bundle-size/README.md @@ -3,7 +3,7 @@ Bundle sizes of small @effect/ui clients, bundled with Vite against the packed @effect/ui and @effect/ui-kit as an external consumer would. Run from the repository root, after `pnpm build`: ```sh -pnpm bundle-size [--app ]... [--development] [--json ] [--base ] [--markdown ] +pnpm bundle-size [--app ]... [--development] [--json ] [--base ] ``` Apps: `counter` (`counter.ts`), `features` (`features.ts`: a Layer, a slot, a failure fallback and the message log) and `routing` (`examples/routing`). Every app is measured unless `--app` picks some. Each bundle runs in happy-dom before it counts. Added gzip bytes are an app's total minus a separately bundled effect-only client. @@ -13,6 +13,5 @@ Apps: `counter` (`counter.ts`), `features` (`features.ts`: a Layer, a slot, a fa | `--development` | bundle without the `production` export condition, keeping development-only checks | | `--json` | write the result to a file | | `--base` | add deltas against an earlier `--json` file; an older single-app file compares the counter only | -| `--markdown` | write the table to a file | The table is also appended to `$GITHUB_STEP_SUMMARY` when that is set. diff --git a/packages/ui/benchmark/bundle-size/run.mjs b/packages/ui/benchmark/bundle-size/run.mjs index 1e523bd2f..f01b905d3 100644 --- a/packages/ui/benchmark/bundle-size/run.mjs +++ b/packages/ui/benchmark/bundle-size/run.mjs @@ -8,13 +8,12 @@ import { parseArgs } from "node:util" import { gzipSync } from "node:zlib" import { build, version as vite } from "vite" -const { values: { app: only, base, development, json, markdown } } = parseArgs({ +const { values: { app: only, base, development, json } } = parseArgs({ options: { app: { type: "string", multiple: true }, development: { type: "boolean", default: false }, base: { type: "string" }, - json: { type: "string" }, - markdown: { type: "string" } + json: { type: "string" } } }) process.env.NODE_ENV = development ? "development" : "production" @@ -338,7 +337,6 @@ const report = [ ].join("\n") console.log(report) if (json) fs.writeFileSync(json, JSON.stringify(result) + "\n") -if (markdown) fs.writeFileSync(markdown, report) if (process.env.GITHUB_STEP_SUMMARY) { fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, report) } From 53c57384690fbe1842f3c952e65bbf81693e4d2f Mon Sep 17 00:00:00 2001 From: Effect Bot Date: Thu, 26 Nov 2026 12:39:05 +0000 Subject: [PATCH 4/4] Match bundle size deltas by variant and survive a bad base file --- .github/workflows/bundle-size-comment.yml | 32 ++++++++++++++--------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/bundle-size-comment.yml b/.github/workflows/bundle-size-comment.yml index 2bc8fb1a1..15431c7c1 100644 --- a/.github/workflows/bundle-size-comment.yml +++ b/.github/workflows/bundle-size-comment.yml @@ -47,19 +47,21 @@ jobs: fi gh run download "$RUN_ID" --name bundle-size --dir sizes [[ -f sizes/base.json ]] || echo null > sizes/base.json - jq -r --slurpfile base sizes/base.json ' - def size: if type == "number" and . == floor and . >= 0 and . < 1e9 then . else error("invalid size") end; - def apps: [.apps[] | { - name: (.name | if IN("counter", "features", "routing") then . else error("unknown app") end), - chunks: (.chunks | size), raw: (.raw | size), gzip: (.gzip | size) - }]; + # Invalid head data fails the job. An unreadable base only turns the deltas into n/a, as in the Check report. + jq -r --rawfile base sizes/base.json ' + def valid: type == "number" and . == floor and . >= 0 and . < 1e9; + def size: if valid then . else error("invalid size") end; def signed: if . > 0 then "+\(.)" else tostring end; def row: "| " + (map(tostring) | join(" | ")) + " |"; - (.baselineGzip | size) as $baseline - | apps as $head - | ($base[0] | if . == null then null else (try (apps | map({key: .name, value: .}) | from_entries) catch {}) end) as $before + .development as $development + | (.baselineGzip | size) as $baseline + | [.apps[] | { + name: (.name | if IN("counter", "features", "routing") then . else error("unknown app") end), + variant, chunks: (.chunks | size), raw: (.raw | size), gzip: (.gzip | size) + }] as $head + | ($base | try fromjson catch {}) as $before | (["App", "Chunks", "Raw bytes", "Gzip bytes", "Added gzip B"] - + if $before then ["Δ raw bytes", "Δ gzip bytes"] else [] end) as $headers + + if $before == null then [] else ["Δ raw bytes", "Δ gzip bytes"] end) as $headers | env.MARKER, "### Bundle size", "", @@ -69,9 +71,13 @@ jobs: ($headers | map("---") | row), ($head[] | . as $app | [.name, .chunks, .raw, .gzip, .gzip - $baseline] - + if $before == null then [] - elif $before[.name] then [($app.raw - $before[.name].raw | signed), ($app.gzip - $before[.name].gzip | signed)] - else ["n/a", "n/a"] end + + if $before == null then [] else + (first($before | objects | select(.development == $development) | .apps | arrays | .[] | objects + | select(.name == $app.name and .variant == $app.variant)) // null) as $old + | if ($old.raw | valid) and ($old.gzip | valid) + then [($app.raw - $old.raw | signed), ($app.gzip - $old.gzip | signed)] + else ["n/a", "n/a"] end + end | row) ' sizes/head.json > body.md ids=$(gh api --paginate "repos/$GH_REPO/issues/$pr/comments?per_page=100" \