-
Notifications
You must be signed in to change notification settings - Fork 62
141 lines (115 loc) · 3.5 KB
/
bundle-size.yml
File metadata and controls
141 lines (115 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Bundle Size
on:
pull_request:
branches:
- main
permissions:
pull-requests: write
jobs:
pr-size:
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: actions/checkout@v5
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- name: Cache turbo build setup
uses: actions/cache@v5
with:
path: .turbo
key: ${{ runner.os }}-turbo-pr-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-pr-
- name: Install and build
run: pnpm install && pnpm build:packages
- name: Measure bundle size
run: node .github/scripts/bundle-size.js --json pr-size.json
- name: Upload size data
uses: actions/upload-artifact@v4
with:
name: pr-size
path: pr-size.json
base-size:
runs-on: ubuntu-latest
steps:
- name: Checkout base
uses: actions/checkout@v5
with:
ref: ${{ github.base_ref }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- name: Cache turbo build setup
uses: actions/cache@v5
with:
path: .turbo
key: ${{ runner.os }}-turbo-base-${{ github.event.pull_request.base.sha }}
restore-keys: |
${{ runner.os }}-turbo-base-
- name: Install and build
run: |
pnpm install
if [ -f .github/scripts/bundle-size.js ]; then
pnpm build:packages
node .github/scripts/bundle-size.js --json base-size.json
else
echo '[]' > base-size.json
fi
- name: Upload size data
uses: actions/upload-artifact@v4
with:
name: base-size
path: base-size.json
report:
runs-on: ubuntu-latest
needs: [pr-size, base-size]
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Download size data
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Generate report
run: >
node .github/scripts/bundle-size-report.js
--pr artifacts/pr-size/pr-size.json
--base artifacts/base-size/base-size.json
> report.md
- name: Post comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const body = fs.readFileSync('report.md', 'utf8');
const marker = '<!-- bundle-size-report -->';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body?.startsWith(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}