From 9e49d9431db3d20592f9aa626c6b18d351e225fb Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 00:20:14 +0500 Subject: [PATCH 1/9] Update workflow for bundle size comparison --- .github/scripts/compare-packages-size.js | 79 +++++++++++++++++------- .github/workflows/pr-diff-size.yml | 10 +-- package.json | 2 +- 3 files changed, 58 insertions(+), 33 deletions(-) diff --git a/.github/scripts/compare-packages-size.js b/.github/scripts/compare-packages-size.js index 172b39e..ea7abcb 100644 --- a/.github/scripts/compare-packages-size.js +++ b/.github/scripts/compare-packages-size.js @@ -3,6 +3,8 @@ import { execSync as exec } from "node:child_process"; import { statSync as stat, existsSync as exists } from "node:fs"; import { globSync as glob } from "glob"; +const MAIN_WORKTREE = ".worktrees/main"; + function size(file) { return exists(file) ? stat(file).size : null; } @@ -17,44 +19,73 @@ function format(bytes) { : `${bytes} B`; } -function delta(a, b) { - if (a == null || b == null) { +function delta(pr, main) { + if (pr == null || main == null) { return null; } - return a - b; + return pr - main; } -function icon(d) { - if (d == null) { +function icon(delta) { + if (delta == null) { return "—"; } - if (d > 0) return "⬆️"; - if (d < 0) return "⬇️"; - return "➡️"; + if (delta > 0) return "🔴"; + if (delta < 0) return "🟢"; + return ""; } -const pr_files = glob("dist/**/*.min.js"); -const pr_sizes = Object.fromEntries(pr_files.map(f => [f, size(f)])); - -exec("git fetch origin main", { stdio: "inherit" }); -exec("git checkout origin/main", { stdio: "ignore" }); -exec("npm ci --include=dev", { stdio: "inherit" }); -exec("npm run build", { stdio: "inherit" }); - -const main_sizes = Object.fromEntries(pr_files.map(f => [f, size(f)])); +function has_local_origin_main() { + try { + exec('git show-ref --verify --quiet refs/remotes/origin/main', { stdio: ["pipe", "pipe", "pipe"] }); + return true; + } + catch { + return false; + } +} -let md = ` +function generate_report(files, pr, main) { + let md = ` ### 📦 Bundle size comparison -| Name | main | PR | Δ | -|------|------|----|---| +| Name | main | PR | Δ | Delta | +|------|-----:|---:|---|-------:| `; -for (const file of pr_files) { - const d = delta(pr_sizes[file], main_sizes[file]); + for (const file of files) { + const d = delta(pr[file], main[file]); + + md += `| ${path.basename(file)} | ${format(main[file])} | ${format(pr[file])} | ${icon(d)} | ${format(d)} |\n`; + } + + console.log(md); - md += `| \`${path.basename(file)}\` | ${format(main_sizes[file])} | ${format(pr_sizes[file])} | ${icon(d)} ${format(d)} |\n`; } -console.log(md); +try { + // + // PR build + // + exec("npm run build", { stdio: "inherit" }); + + const pr_files = glob("dist/**/*.min.js"); + const pr_sizes = Object.fromEntries(pr_files.map(f => [f, size(f)])); + + // + // Main build + // + has_local_origin_main() || exec("git fetch origin main", { stdio: "inherit" }); + exec(`git worktree add ${MAIN_WORKTREE} origin/main`, { stdio: "ignore" }); + exec("npm ci --include=dev", { cwd: MAIN_WORKTREE, stdio: "inherit" }); + exec("npm run build", { cwd: MAIN_WORKTREE, stdio: "inherit" }); + + const main_sizes = Object.fromEntries( + pr_files.map(f => [f, size(path.join(MAIN_WORKTREE, f))])); + + generate_report(pr_files, pr_sizes, main_sizes); +} +finally { + exec(`git worktree remove ${MAIN_WORKTREE}`, { stdio: "inherit" }); +} diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index 691562d..a4f0dfa 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -27,16 +27,10 @@ jobs: uses: actions/checkout@v4 - name: Install Dependencies - run: npm ci - - - name: Build - run: npm run build - env: - NODE_ENV: production - SKIP_GIT_TAG_RESOLUTION: true + run: npm ci --include=dev - name: Run size comparison - run: npm run size-diff-report > comment.md + run: npm run size-report > comment.md env: NODE_ENV: production SKIP_GIT_TAG_RESOLUTION: true diff --git a/package.json b/package.json index a18dfaa..e3f7e32 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "scripts": { "build": "cross-env NODE_ENV=production gulp build", "build:debug": "gulp build", - "size-diff-report": "node .github/scripts/compare-packages-size.js", + "size-report": "cross-env NODE_ENV=production SKIP_GIT_TAG_RESOLUTION=true node .github/scripts/compare-packages-size.js", "test": "gulp build && vitest run && playwright test", "test:playwright": "playwright test", "test:vitest": "vitest run" From f05f1cf90e3e45bef013ddaac8e90a78ffac55bd Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 00:26:55 +0500 Subject: [PATCH 2/9] Use context.issue.number instead of workflow_run payload --- .github/workflows/pr-diff-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index a4f0dfa..dd3c864 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -41,7 +41,7 @@ jobs: script: | const fs = require('fs'); const body = fs.readFileSync('./comment.md', 'utf8'); - const pr_number = context.payload.workflow_run.pull_requests[0].number; + const pr_number = context.issue.number; const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, From a3dfd33bae7281fe4fd4ce13c2c5d6b916368eb4 Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 00:41:58 +0500 Subject: [PATCH 3/9] Write size report to a temp file passed from workflow --- .github/scripts/compare-packages-size.js | 4 ++-- .github/workflows/pr-diff-size.yml | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/scripts/compare-packages-size.js b/.github/scripts/compare-packages-size.js index ea7abcb..b1e6a5c 100644 --- a/.github/scripts/compare-packages-size.js +++ b/.github/scripts/compare-packages-size.js @@ -1,6 +1,6 @@ import path from "node:path"; import { execSync as exec } from "node:child_process"; -import { statSync as stat, existsSync as exists } from "node:fs"; +import { statSync as stat, existsSync as exists, writeFileSync as write_file } from "node:fs"; import { globSync as glob } from "glob"; const MAIN_WORKTREE = ".worktrees/main"; @@ -61,7 +61,7 @@ function generate_report(files, pr, main) { } console.log(md); - + process.env.SIZE_REPORT_OUTPUT && write_file(process.env.SIZE_REPORT_OUTPUT, md.trim()); } try { diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index dd3c864..085210b 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -30,17 +30,18 @@ jobs: run: npm ci --include=dev - name: Run size comparison - run: npm run size-report > comment.md + run: npm run size-report env: NODE_ENV: production SKIP_GIT_TAG_RESOLUTION: true + SIZE_REPORT_OUTPUT: ${{ runner.temp }}/comment-${{ github.event.issue.number }}.md - name: Comment PR uses: actions/github-script@v7 with: script: | const fs = require('fs'); - const body = fs.readFileSync('./comment.md', 'utf8'); + const body = fs.readFileSync(process.env.SIZE_REPORT_OUTPUT, 'utf8'); const pr_number = context.issue.number; const { data: comments } = await github.rest.issues.listComments({ From 487a364a7b6d79ef6b8a8c638d18e634c04d0ffb Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 00:47:07 +0500 Subject: [PATCH 4/9] Make SIZE_REPORT_OUTPUT available across workflow steps --- .github/workflows/pr-diff-size.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index 085210b..f5e5cba 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -15,6 +15,8 @@ jobs: if: github.repository == 'rameel/ramstack.alpinegear.js' runs-on: ubuntu-latest + env: + SIZE_REPORT_OUTPUT: ${{ runner.temp }}/comment-${{ github.event.issue.number }}.md steps: - name: Setup Node.js @@ -34,7 +36,6 @@ jobs: env: NODE_ENV: production SKIP_GIT_TAG_RESOLUTION: true - SIZE_REPORT_OUTPUT: ${{ runner.temp }}/comment-${{ github.event.issue.number }}.md - name: Comment PR uses: actions/github-script@v7 From 1be4c7326bee76e4b825ffe6e538016fb0fac765 Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 00:54:01 +0500 Subject: [PATCH 5/9] Update workflow --- .github/workflows/pr-diff-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index f5e5cba..47ecc42 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest env: - SIZE_REPORT_OUTPUT: ${{ runner.temp }}/comment-${{ github.event.issue.number }}.md + SIZE_REPORT_OUTPUT: ${{ runner.temp }}/comment-${{ github.context.issue.number }}.md steps: - name: Setup Node.js From 73b51702f0d970af37e513732bb3fd2048a5ab63 Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 00:58:30 +0500 Subject: [PATCH 6/9] Update wokflow --- .github/workflows/pr-diff-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index 47ecc42..0e27405 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest env: - SIZE_REPORT_OUTPUT: ${{ runner.temp }}/comment-${{ github.context.issue.number }}.md + SIZE_REPORT_OUTPUT: ${{ runner.temp }}/comment-${{ github.event.pull_request.number }}.md steps: - name: Setup Node.js From f61433d4e2400fe99c63bbe452241bc8b3929288 Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 01:06:26 +0500 Subject: [PATCH 7/9] Update workflow --- .github/workflows/pr-diff-size.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index 0e27405..b4090e8 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -31,6 +31,9 @@ jobs: - name: Install Dependencies run: npm ci --include=dev + - name: Prepate report path + run: echo "${{ runner.temp }}/comment-${{ github.event.pull_request.number }}.md" >> $GITHUB_ENV + - name: Run size comparison run: npm run size-report env: From 6c89fbbab4ac53a4c708331da2b509ee8cf49a06 Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 01:08:36 +0500 Subject: [PATCH 8/9] Update workflow --- .github/workflows/pr-diff-size.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index b4090e8..d356764 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -32,7 +32,7 @@ jobs: run: npm ci --include=dev - name: Prepate report path - run: echo "${{ runner.temp }}/comment-${{ github.event.pull_request.number }}.md" >> $GITHUB_ENV + run: echo "SIZE_REPORT_OUTPUT=$RUNNER_TEMP/comment-${{ github.event.pull_request.number }}.md" >> $GITHUB_ENV - name: Run size comparison run: npm run size-report From 1b58131bde38f22d58331e2346066d75ded1ed1d Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 8 Jan 2026 01:10:06 +0500 Subject: [PATCH 9/9] Update workflow --- .github/workflows/pr-diff-size.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pr-diff-size.yml b/.github/workflows/pr-diff-size.yml index d356764..5ebbd61 100644 --- a/.github/workflows/pr-diff-size.yml +++ b/.github/workflows/pr-diff-size.yml @@ -15,8 +15,6 @@ jobs: if: github.repository == 'rameel/ramstack.alpinegear.js' runs-on: ubuntu-latest - env: - SIZE_REPORT_OUTPUT: ${{ runner.temp }}/comment-${{ github.event.pull_request.number }}.md steps: - name: Setup Node.js