Skip to content

Commit 252082b

Browse files
authored
[Bundle size] GH Action for reporting bundle size (#896)
* wip: bundle size comment test * wip: try minifying autofill.js * move to scripts * fix: step id * feat: unminify bundle * remove test script * update comment * test commit to check update * find previous comment
1 parent c48e1d1 commit 252082b

13 files changed

+154
-148
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Bundle Size Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
bundle-size-check:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '22.0.0'
21+
cache: 'npm'
22+
23+
- name: Install dependencies
24+
run: npm ci
25+
26+
- name: Build project
27+
run: npm run build
28+
29+
- name: Calculate current bundle size
30+
id: current-calculation
31+
run: |
32+
echo "current_size_js=$(du -sb dist/autofill.js | cut -f1)" >> $GITHUB_OUTPUT
33+
echo "current_size_js_debug=$(du -sb dist/autofill-debug.js | cut -f1)" >> $GITHUB_OUTPUT
34+
35+
- name: Get base commit and calculate base size
36+
id: base-calculation
37+
run: |
38+
# Get base commit SHA
39+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
40+
41+
# Checkout base commit
42+
git checkout $BASE_SHA
43+
44+
# Install dependencies and build
45+
npm ci
46+
npm run build
47+
48+
# Calculate base size
49+
echo "base_size_js=$(du -sb dist/autofill.js | cut -f1)" >> $GITHUB_OUTPUT
50+
echo "base_size_js_debug=$(du -sb dist/autofill-debug.js | cut -f1)" >> $GITHUB_OUTPUT
51+
52+
# Return to current commit
53+
git checkout ${{ github.sha }}
54+
npm ci
55+
npm run build
56+
57+
- name: Find Previous Comment
58+
uses: peter-evans/find-comment@v3
59+
id: find_comment
60+
with:
61+
issue-number: ${{ github.event.pull_request.number }}
62+
comment-author: 'github-actions[bot]'
63+
body-includes: 'Bundle size change'
64+
direction: last
65+
66+
- name: Generate bundle size comment
67+
id: generate-comment
68+
run: |
69+
# Set environment variables for the script
70+
export BASE_SIZE_JS="${{ steps.base-calculation.outputs.base_size_js }}"
71+
export CURRENT_SIZE_JS="${{ steps.current-calculation.outputs.current_size_js }}"
72+
export BASE_SIZE_JS_DEBUG="${{ steps.base-calculation.outputs.base_size_js_debug }}"
73+
export CURRENT_SIZE_JS_DEBUG="${{ steps.current-calculation.outputs.current_size_js_debug }}"
74+
75+
# Run the script and capture output
76+
# If there is a size change, run the script and capture output
77+
if [ "$BASE_SIZE_JS" != "$CURRENT_SIZE_JS" ] || [ "$BASE_SIZE_JS_DEBUG" != "$CURRENT_SIZE_JS_DEBUG" ]; then
78+
npm run bundle-size-check > comment.txt
79+
fi
80+
81+
commentBody=$(cat comment.txt)
82+
echo "comment_body<<EOF" >> $GITHUB_OUTPUT
83+
echo "$commentBody" >> $GITHUB_OUTPUT
84+
echo "EOF" >> $GITHUB_OUTPUT
85+
86+
- name: Create, or Update the Comment
87+
uses: peter-evans/create-or-update-comment@v4
88+
with:
89+
issue-number: ${{ github.event.pull_request.number }}
90+
comment-id: ${{ steps.find_comment.outputs.comment-id }}
91+
body: ${{ steps.generate-comment.outputs.comment_body }}
92+
edit-mode: replace

dist/autofill-debug.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/autofill.css

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/autofill.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"verify:local": "npm run lint:fix && npm run tsc && npm run test:unit && npm run test:integration",
3434
"serve": "http-server -c-1 --port 3210 ./",
3535
"debug-form": "node scripts/debug-form.js",
36-
"debug-ui": "node scripts/debug-ui.js"
36+
"debug-ui": "node scripts/debug-ui.js",
37+
"bundle-size-check": "node scripts/bundle-size-check.js"
3738
},
3839
"license": "Apache-2.0",
3940
"devDependencies": {

scripts/bundle-size-check.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Bundle Size Comment Generator
5+
* This script generates comments for PRs showing bundle size differences
6+
*/
7+
8+
function formatBytes(bytes) {
9+
if (bytes === 0) return '0 B';
10+
const k = 1024;
11+
const sizes = ['B', 'KB', 'MB', 'GB'];
12+
const i = Math.floor(Math.log(bytes) / Math.log(k));
13+
return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
14+
}
15+
16+
function generateBundleSizeComment(baseSizes, currentSizes) {
17+
const { js: baseSizeJs, jsDebug: baseSizeJsDebug } = baseSizes;
18+
const { js: currentSizeJs, jsDebug: currentSizeJsDebug } = currentSizes;
19+
20+
const sizeDiffJs = currentSizeJs - baseSizeJs;
21+
const percentChangeJs = ((sizeDiffJs / baseSizeJs) * 100).toFixed(2);
22+
23+
const sizeDiffJsDebug = currentSizeJsDebug - baseSizeJsDebug;
24+
const percentChangeJsDebug = ((sizeDiffJsDebug / baseSizeJsDebug) * 100).toFixed(2);
25+
26+
return `## Bundle size change (main vs. current)
27+
**autofill.js:** ${formatBytes(baseSizeJs)} -> ${formatBytes(currentSizeJs)}
28+
**Change:** ${sizeDiffJs > 0 ? '+' : ''}${formatBytes(Math.abs(sizeDiffJs))} (${sizeDiffJs > 0 ? '+' : ''}${percentChangeJs}%)
29+
<br>
30+
**autofill-debug.js:** ${formatBytes(baseSizeJsDebug)} -> ${formatBytes(currentSizeJsDebug)}
31+
**Change:** ${sizeDiffJsDebug > 0 ? '+' : ''}${formatBytes(Math.abs(sizeDiffJsDebug))} (${sizeDiffJsDebug > 0 ? '+' : ''}${percentChangeJsDebug}%)`;
32+
}
33+
34+
if (require.main === module) {
35+
const baseSizes = {
36+
js: parseInt(process.env.BASE_SIZE_JS || '0'),
37+
jsDebug: parseInt(process.env.BASE_SIZE_JS_DEBUG || '0'),
38+
};
39+
40+
const currentSizes = {
41+
js: parseInt(process.env.CURRENT_SIZE_JS || '0'),
42+
jsDebug: parseInt(process.env.CURRENT_SIZE_JS_DEBUG || '0'),
43+
};
44+
45+
// Generate and output the comment
46+
const comment = generateBundleSizeComment(baseSizes, currentSizes);
47+
console.log(comment);
48+
}

src/UI/img/credit-card-amex.svg

Lines changed: 1 addition & 6 deletions
Loading
4.82 KB
Loading

0 commit comments

Comments
 (0)