Skip to content

Commit 381ccff

Browse files
Use dynamic bundle size limits (base branch + 0.5KB)
- Remove static limits from .size-limit.json - Workflow now fetches base branch sizes first - Dynamically calculates limits as base_size + 512 bytes - Supports any PR base branch, not just master - Simplified to track only gzip sizes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent cb43b6c commit 381ccff

File tree

2 files changed

+58
-71
lines changed

2 files changed

+58
-71
lines changed

.github/workflows/bundle-size.yml

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ name: Bundle Size
22

33
on:
44
pull_request:
5-
branches:
6-
- master
7-
paths:
8-
- 'packages/**'
9-
- 'package.json'
10-
- 'pnpm-lock.yaml'
11-
- '.size-limit.json'
12-
- '.github/workflows/bundle-size.yml'
13-
push:
14-
branches:
15-
- master
165
paths:
176
- 'packages/**'
187
- 'package.json'
@@ -29,34 +18,74 @@ jobs:
2918
env:
3019
CI_JOB_NUMBER: 1
3120
steps:
32-
- name: Checkout
33-
uses: actions/checkout@v4
34-
with:
35-
persist-credentials: false
36-
3721
- name: Setup Node
3822
uses: actions/setup-node@v4
3923
with:
4024
node-version: '22'
4125

4226
- name: Setup pnpm
4327
uses: pnpm/action-setup@v4
28+
with:
29+
version: 9
4430

45-
- name: Get pnpm store directory
46-
shell: bash
47-
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
48-
49-
- name: Setup pnpm cache
50-
uses: actions/cache@v4
31+
# 1. Get base branch sizes first
32+
- name: Checkout base branch
33+
uses: actions/checkout@v4
5134
with:
52-
path: ${{ env.STORE_PATH }}
53-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
54-
restore-keys: |
55-
${{ runner.os }}-pnpm-store-
35+
ref: ${{ github.base_ref }}
36+
37+
- name: Install base dependencies
38+
run: pnpm install --frozen-lockfile
39+
40+
- name: Build and measure base branch
41+
run: |
42+
pnpm run build
43+
npx size-limit --json > /tmp/base-sizes.json
44+
echo "Base branch sizes:"
45+
cat /tmp/base-sizes.json
46+
47+
# 2. Checkout PR and set dynamic limits
48+
- name: Checkout PR branch
49+
uses: actions/checkout@v4
50+
51+
- name: Install PR dependencies
52+
run: pnpm install --frozen-lockfile
53+
54+
- name: Set dynamic limits (base + 0.5KB)
55+
run: |
56+
node -e "
57+
const fs = require('fs');
58+
const baseSizes = JSON.parse(fs.readFileSync('/tmp/base-sizes.json', 'utf8'));
59+
const config = JSON.parse(fs.readFileSync('.size-limit.json', 'utf8'));
60+
61+
const THRESHOLD = 512; // 0.5 KB in bytes
62+
63+
console.log('Setting dynamic limits (base + 0.5KB):');
64+
console.log('');
65+
66+
config.forEach(entry => {
67+
const baseEntry = baseSizes.find(b => b.name === entry.name);
68+
if (baseEntry) {
69+
const limit = baseEntry.size + THRESHOLD;
70+
entry.limit = limit + ' B';
71+
console.log(entry.name + ':');
72+
console.log(' base size: ' + (baseEntry.size / 1024).toFixed(2) + ' kB');
73+
console.log(' limit: ' + (limit / 1024).toFixed(2) + ' kB');
74+
console.log('');
75+
} else {
76+
console.log(entry.name + ': No base entry found, keeping original limit');
77+
}
78+
});
79+
80+
fs.writeFileSync('.size-limit.json', JSON.stringify(config, null, 2));
81+
console.log('Updated .size-limit.json');
82+
"
5683
84+
# 3. Run the action with dynamic limits
5785
- name: Check bundle size
5886
uses: andresz1/size-limit-action@v1
5987
with:
6088
github_token: ${{ secrets.GITHUB_TOKEN }}
6189
package_manager: pnpm
6290
build_script: build
91+
skip_step: install

.size-limit.json

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,17 @@
11
[
2-
{
3-
"name": "react-on-rails (raw)",
4-
"path": "packages/react-on-rails/lib/*.js",
5-
"gzip": false,
6-
"brotli": false,
7-
"limit": "50 kB"
8-
},
92
{
103
"name": "react-on-rails (gzip)",
114
"path": "packages/react-on-rails/lib/*.js",
12-
"gzip": true,
13-
"limit": "20 kB"
14-
},
15-
{
16-
"name": "react-on-rails (brotli)",
17-
"path": "packages/react-on-rails/lib/*.js",
18-
"brotli": true,
19-
"limit": "15 kB"
20-
},
21-
{
22-
"name": "react-on-rails-pro (raw)",
23-
"path": "packages/react-on-rails-pro/lib/*.js",
24-
"gzip": false,
25-
"brotli": false,
26-
"limit": "100 kB"
5+
"gzip": true
276
},
287
{
298
"name": "react-on-rails-pro (gzip)",
309
"path": "packages/react-on-rails-pro/lib/*.js",
31-
"gzip": true,
32-
"limit": "45 kB"
33-
},
34-
{
35-
"name": "react-on-rails-pro (brotli)",
36-
"path": "packages/react-on-rails-pro/lib/*.js",
37-
"brotli": true,
38-
"limit": "40 kB"
39-
},
40-
{
41-
"name": "react-on-rails-pro-node-renderer (raw)",
42-
"path": "packages/react-on-rails-pro-node-renderer/lib/*.js",
43-
"gzip": false,
44-
"brotli": false,
45-
"limit": "35 kB"
10+
"gzip": true
4611
},
4712
{
4813
"name": "react-on-rails-pro-node-renderer (gzip)",
4914
"path": "packages/react-on-rails-pro-node-renderer/lib/*.js",
50-
"gzip": true,
51-
"limit": "15 kB"
52-
},
53-
{
54-
"name": "react-on-rails-pro-node-renderer (brotli)",
55-
"path": "packages/react-on-rails-pro-node-renderer/lib/*.js",
56-
"brotli": true,
57-
"limit": "12 kB"
15+
"gzip": true
5816
}
5917
]

0 commit comments

Comments
 (0)