Skip to content

Commit 424f736

Browse files
committed
feat(ci): add bundle size comparison and setup pnpm action
1 parent 7949c46 commit 424f736

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

.github/actions/setup-pnpm/action.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: "Setup pnpm"
2+
description: "Install Node.js and pnpm and set up caching"
3+
inputs:
4+
node-version:
5+
description: "Version of Node.js to use"
6+
required: false
7+
default: "22"
8+
pnpm-version:
9+
description: "Version of pnpm to install"
10+
required: false
11+
default: "9.1.0"
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: ${{ inputs.node-version }}
19+
cache: "pnpm"
20+
21+
- name: Enable Corepack
22+
run: corepack enable
23+
24+
- name: Install pnpm
25+
run: corepack prepare pnpm@${{ inputs.pnpm-version }} --activate
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
on:
2+
pull_request:
3+
pull_request_target:
4+
5+
jobs:
6+
# Build and upload stats for `head`
7+
build:
8+
name: 'Build and upload for ${{ matrix.target }}'
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
strategy:
13+
matrix:
14+
target: [browser, node] # Runs for both browser and node bundles
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
ref: ${{ github.event.pull_request.head.ref }}
19+
- name: Setup pnpm
20+
uses: .github/actions/setup-pnpm
21+
- name: Install dependencies
22+
run: pnpm install --frozen-lockfile
23+
- name: Build
24+
run: pnpm build:clean
25+
env:
26+
NODE_ENV: production
27+
- name: Upload stats.json
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: head-stats-${{ matrix.target }}
31+
path: .stats/bundle.${{ matrix.target }}.json
32+
33+
# Build base stats for comparison
34+
build-base:
35+
name: 'Build base and upload for ${{ matrix.target }}'
36+
runs-on: ubuntu-latest
37+
permissions:
38+
contents: read
39+
strategy:
40+
matrix:
41+
target: [browser, node]
42+
steps:
43+
- uses: actions/checkout@v4
44+
with:
45+
ref: ${{ github.base_ref }}
46+
- name: Setup pnpm
47+
uses: .github/actions/setup-pnpm
48+
- name: Install dependencies
49+
run: pnpm install --frozen-lockfile
50+
- name: Build
51+
run: pnpm build:clean
52+
env:
53+
NODE_ENV: production
54+
- name: Upload stats.json
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: base-stats-${{ matrix.target }}
58+
path: .stats/bundle.${{ matrix.target }}.json
59+
60+
# Compare base and head stats.json files
61+
compare:
62+
name: 'Compare base & head bundle sizes for ${{ matrix.target }}'
63+
runs-on: ubuntu-latest
64+
needs: [build, build-base]
65+
permissions:
66+
pull-requests: write
67+
strategy:
68+
matrix:
69+
target: [browser, node]
70+
steps:
71+
- uses: actions/download-artifact@v4
72+
with:
73+
name: head-stats-${{ matrix.target }}
74+
- uses: actions/download-artifact@v4
75+
with:
76+
name: base-stats-${{ matrix.target }}
77+
- uses: twk3/rollup-size-compare-action@v1.0.0
78+
with:
79+
github-token: ${{ secrets.GITHUB_TOKEN }}
80+
current-stats-json-path: ./head-stats-${{ matrix.target }}/bundle.${{ matrix.target }}.json
81+
base-stats-json-path: ./base-stats-${{ matrix.target }}/bundle.${{ matrix.target }}.json

rollup.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const node_build = {
6767
// Only minify in production
6868
isProduction && terser(),
6969
// Analysis and visualization artifacts
70-
visualizer({ filename: '.stats/bundle.node.html', template: 'raw-data' }),
70+
visualizer({ filename: '.stats/bundle.node.json', template: 'raw-data' }),
7171
],
7272
};
7373

@@ -126,7 +126,7 @@ const browser_build = {
126126
// Minify the code
127127
terser(),
128128
// Analysis and visualization artifacts
129-
visualizer({ filename: '.stats/bundle.browser.html', template: 'raw-data' }),
129+
visualizer({ filename: '.stats/bundle.browser.json', template: 'raw-data' }),
130130
],
131131
};
132132

0 commit comments

Comments
 (0)