Skip to content

Commit cfe260e

Browse files
committed
feat(cicd): add bundle stats comparison
1 parent 7015095 commit cfe260e

File tree

3 files changed

+120
-4
lines changed

3 files changed

+120
-4
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ jobs:
6868
NODE_OPTIONS: '--max_old_space_size=4096'
6969
# We want to ensure that static exports for all locales do not occur on `pull_request` events
7070
NEXT_PUBLIC_STATIC_EXPORT_LOCALE: ${{ github.event_name == 'push' }}
71+
# See https://github.com/vercel/next.js/pull/81318
72+
TURBOPACK_STATS: ${{ matrix.os == 'ubuntu-latest' }}
73+
74+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
75+
if: matrix.os == 'ubuntu-latest'
76+
with:
77+
name: webpack-stats
78+
path: apps/site/.next/server/webpack-stats.json
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Compare Bundle Size
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build"]
6+
types: [completed]
7+
8+
permissions:
9+
contents: read
10+
actions: read
11+
# To create the comment
12+
pull-requests: write
13+
14+
jobs:
15+
compare:
16+
name: Compare Bundle Stats
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Harden Runner
21+
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
22+
with:
23+
egress-policy: audit
24+
25+
- name: Download PR artifact (head)
26+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
27+
with:
28+
script: |
29+
const fs = require('fs');
30+
const path = require('path');
31+
32+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
run_id: context.payload.workflow_run.id,
36+
});
37+
38+
const artifact = artifacts.data.artifacts.find(a => a.name === 'webpack-stats');
39+
40+
if (!artifact) {
41+
throw new Error('No artifact found!');
42+
}
43+
44+
const download = await github.rest.actions.downloadArtifact({
45+
owner: context.repo.owner,
46+
repo: context.repo.repo,
47+
artifact_id: artifact.id,
48+
archive_format: 'zip',
49+
});
50+
51+
fs.mkdirSync('head-stats', { recursive: true });
52+
fs.writeFileSync('head-stats/stats.zip', Buffer.from(download.data));
53+
54+
- name: Download main branch artifact (base)
55+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
56+
with:
57+
script: |
58+
const fs = require('fs');
59+
60+
const runs = await github.rest.actions.listWorkflowRuns({
61+
owner: context.repo.owner,
62+
repo: context.repo.repo,
63+
workflow_id: context.payload.workflow_run.workflow_id,
64+
branch: 'main',
65+
status: 'completed',
66+
per_page: 1,
67+
});
68+
69+
if (runs.length < 1) {
70+
throw new Error('No runs found!');
71+
}
72+
73+
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
run_id: runs.data.workflow_runs[0].id,
77+
});
78+
79+
const artifact = artifacts.data.artifacts.find(a => a.name === 'webpack-stats');
80+
81+
if (!artifact) {
82+
throw new Error('No artifact found!');
83+
}
84+
85+
const download = await github.rest.actions.downloadArtifact({
86+
owner: context.repo.owner,
87+
repo: context.repo.repo,
88+
artifact_id: artifact.id,
89+
archive_format: 'zip',
90+
});
91+
92+
fs.mkdirSync('base-stats', { recursive: true });
93+
fs.writeFileSync('base-stats/stats.zip', Buffer.from(download.data));
94+
95+
- name: Unzip artifacts
96+
run: |
97+
unzip -o head-stats/stats.zip -d head-stats
98+
unzip -o base-stats/stats.zip -d base-stats
99+
100+
- uses: github/webpack-bundlesize-compare-action@89161bb25577f08577ce053c3264c0e3b7d7558f # v2.1.0
101+
with:
102+
github-token: ${{ secrets.GITHUB_TOKEN }}
103+
current-stats-json-path: ./head-stats/webpack-stats.json
104+
base-stats-json-path: ./base-stats/webpack-stats.json

apps/site/turbo.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"NEXT_PUBLIC_ORAMA_ENDPOINT",
2020
"NEXT_PUBLIC_DATA_URL",
2121
"TURBO_CACHE",
22-
"TURBO_TELEMETRY_DISABLED"
22+
"TURBO_TELEMETRY_DISABLED",
23+
"TURBOPACK_STATS"
2324
]
2425
},
2526
"build": {
@@ -45,7 +46,8 @@
4546
"NEXT_PUBLIC_ORAMA_ENDPOINT",
4647
"NEXT_PUBLIC_DATA_URL",
4748
"TURBO_CACHE",
48-
"TURBO_TELEMETRY_DISABLED"
49+
"TURBO_TELEMETRY_DISABLED",
50+
"TURBOPACK_STATS"
4951
]
5052
},
5153
"start": {
@@ -64,7 +66,8 @@
6466
"NEXT_PUBLIC_ORAMA_ENDPOINT",
6567
"NEXT_PUBLIC_DATA_URL",
6668
"TURBO_CACHE",
67-
"TURBO_TELEMETRY_DISABLED"
69+
"TURBO_TELEMETRY_DISABLED",
70+
"TURBOPACK_STATS"
6871
]
6972
},
7073
"deploy": {
@@ -89,7 +92,8 @@
8992
"NEXT_PUBLIC_ORAMA_ENDPOINT",
9093
"NEXT_PUBLIC_DATA_URL",
9194
"TURBO_CACHE",
92-
"TURBO_TELEMETRY_DISABLED"
95+
"TURBO_TELEMETRY_DISABLED",
96+
"TURBOPACK_STATS"
9397
]
9498
},
9599
"lint:js": {

0 commit comments

Comments
 (0)