-
Notifications
You must be signed in to change notification settings - Fork 6
106 lines (89 loc) · 3.32 KB
/
bundle-size.yml
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
name: Size
on:
pull_request:
branches:
- main
jobs:
size:
name: Report bundle and install size
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout base branch
uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies (base)
run: bun install
- name: Build (base)
run: bun run build
- name: Get base bundle size
id: base-bundle-size
run: |
echo "base=$(du -sh dist | cut -f1)" >> $GITHUB_OUTPUT
- name: Get base install size
id: base-install-size
run: |
echo "base=$(bunx howfat -r simple . | grep 'Size:' | awk '{print $2}')" >> $GITHUB_OUTPUT
- name: Checkout PR branch
uses: actions/checkout@v3
- name: Install dependencies (PR)
run: bun install
- name: Build (PR)
run: bun run build
- name: Get PR bundle size
id: pr-bundle-size
run: |
echo "pr=$(du -sh dist | cut -f1)" >> $GITHUB_OUTPUT
- name: Get PR install size and full howfat output
id: pr-install-size
run: |
echo "pr=$(bunx howfat -r simple . | grep 'Size:' | awk '{print $2}')" >> $GITHUB_OUTPUT
echo "full_output<<EOF" >> $GITHUB_OUTPUT
bunx howfat -r table . >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Calculate bundle size difference
id: bundle-size-diff
run: |
base_size=$(echo ${{ steps.base-bundle-size.outputs.base }} | sed 's/[^0-9.]*//g')
pr_size=$(echo ${{ steps.pr-bundle-size.outputs.pr }} | sed 's/[^0-9.]*//g')
diff=$(echo "$pr_size - $base_size" | bc)
if (( $(echo "$diff > 0" | bc -l) )); then
echo "diff=+$diff" >> $GITHUB_OUTPUT
else
echo "diff=$diff" >> $GITHUB_OUTPUT
fi
- name: Calculate install size difference
id: install-size-diff
run: |
base_size=$(echo ${{ steps.base-install-size.outputs.base }} | sed 's/[^0-9.]*//g')
pr_size=$(echo ${{ steps.pr-install-size.outputs.pr }} | sed 's/[^0-9.]*//g')
diff=$(echo "$pr_size - $base_size" | bc)
if (( $(echo "$diff > 0" | bc -l) )); then
echo "diff=+$diff" >> $GITHUB_OUTPUT
else
echo "diff=$diff" >> $GITHUB_OUTPUT
fi
- name: Update comment
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
header: Size Report
message: |
## Size Report
### Bundle Size
- Base branch size: ${{ steps.base-bundle-size.outputs.base }}
- PR branch size: ${{ steps.pr-bundle-size.outputs.pr }}
- Difference: ${{ steps.bundle-size-diff.outputs.diff }}
### Install Size
- Base branch size: ${{ steps.base-install-size.outputs.base }}
- PR branch size: ${{ steps.pr-install-size.outputs.pr }}
- Difference: ${{ steps.install-size-diff.outputs.diff }}
### Full Howfat Output (PR Branch)
```
${{ steps.pr-install-size.outputs.full_output }}
```