-
Notifications
You must be signed in to change notification settings - Fork 3
84 lines (68 loc) · 2.23 KB
/
size-check.yml
File metadata and controls
84 lines (68 loc) · 2.23 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
name: Bundle Size Check
on:
pull_request:
branches: [master, develop]
permissions:
contents: read
pull-requests: write
jobs:
size:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build packages
run: pnpm build
- name: Check bundle sizes
id: size-check
run: |
# Create report
REPORT="## 📦 Bundle Size Report\n\n"
REPORT+="| Package | Size | Gzipped |\n"
REPORT+="|---------|------|---------|"
for pkg in packages/*/dist/index.js; do
if [ -f "$pkg" ]; then
name=$(echo $pkg | cut -d'/' -f2)
size=$(stat -f%z "$pkg" 2>/dev/null || stat -c%s "$pkg" 2>/dev/null || echo "0")
gzip_size=$(gzip -c "$pkg" | wc -c)
size_kb=$((size / 1024))
gzip_kb=$((gzip_size / 1024))
REPORT+="\n| $name | ${size_kb}KB | ${gzip_kb}KB |"
fi
done
# Save to step summary
echo -e "$REPORT" >> $GITHUB_STEP_SUMMARY
# Save to output file for PR comment
echo -e "$REPORT" > size-report.txt
- name: Comment PR
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
script: |
const fs = require('fs');
let body = '';
try {
body = fs.readFileSync('size-report.txt', 'utf8');
} catch (error) {
body = '## 📦 Bundle Size Report\n\nNo bundle files found to analyze.';
}
if (!body || body.trim() === '') {
body = '## 📦 Bundle Size Report\n\nNo bundle files found to analyze.';
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});