-
Notifications
You must be signed in to change notification settings - Fork 41
103 lines (85 loc) · 2.76 KB
/
frontend-bundle-check.yml
File metadata and controls
103 lines (85 loc) · 2.76 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
name: Frontend Bundle Size Check
on:
pull_request:
permissions:
contents: read
jobs:
build-base-branch:
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
size: ${{ steps.get-size.outputs.size }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.pull_request.base.ref }}
persist-credentials: false
- name: Prepare
uses: ./.github/actions/prepare
- name: Build project
run: npm run build
- name: Get bundle size
id: get-size
run: |
SIZE=$(du -sk build/_app/immutable/**/*.js{,.gz} 2>/dev/null | awk '{sum += $1} END {print sum}')
echo "Base branch bundle size: $SIZE KB"
echo "size=$SIZE" >> $GITHUB_OUTPUT
build-pr:
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
size: ${{ steps.get-size.outputs.size }}
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: false
- name: Prepare
uses: ./.github/actions/prepare
- name: Build project
run: npm run build
- name: Get bundle size
id: get-size
run: |
SIZE=$(du -sk build/_app/immutable/**/*.js{,.gz} 2>/dev/null | awk '{sum += $1} END {print sum}')
echo "PR bundle size: $SIZE KB"
echo "size=$SIZE" >> $GITHUB_OUTPUT
compare-sizes:
needs: [build-base-branch, build-pr]
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: Compare bundle sizes
run: |
BASE_SIZE=$BASE_SIZE
PR_SIZE=$PR_SIZE
DIFF=$((PR_SIZE - BASE_SIZE))
if (( BASE_SIZE > 0 )); then
PERCENT=$((100 * DIFF / BASE_SIZE))
else
PERCENT=0
fi
echo "Base bundle size: ${BASE_SIZE} KB"
echo "PR bundle size: ${PR_SIZE} KB"
echo "::notice::Difference: ${DIFF} KB"
echo "::notice::Percent change: ${PERCENT}%"
echo "::endgroup::"
MAX_KB=100
MAX_PERCENT=10
if (( DIFF > MAX_KB )); then
echo "🚨 Bundle size increased by ${DIFF}KB, over the limit of ${MAX_KB}KB."
exit 1
fi
if (( PERCENT > MAX_PERCENT )); then
echo "🚨 Bundle size increased by ${PERCENT}%, over the limit of ${MAX_PERCENT}%."
exit 1
fi
echo "✅ Bundle size within acceptable limits."
env:
BASE_SIZE: ${{ needs.build-base-branch.outputs.size }}
PR_SIZE: ${{ needs.build-pr.outputs.size }}