-
Notifications
You must be signed in to change notification settings - Fork 106
151 lines (130 loc) · 5.4 KB
/
bundle-size.yml
File metadata and controls
151 lines (130 loc) · 5.4 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
142
143
144
145
146
147
148
149
150
151
name: Bundle Size
on:
push:
branches: [main]
# No path filter on main - we need to generate baseline on every push
# so PRs always compare against the latest main, even if main has
# commits that don't touch explorer (e.g., workflow changes, other apps)
pull_request:
types: [opened, reopened, synchronize]
paths:
- "apps/explorer/**"
- "pnpm-lock.yaml"
permissions: {}
concurrency:
group: bundle-size-${{ github.head_ref || github.ref }}
cancel-in-progress: true
env:
NODE_ENV: production
NODE_OPTIONS: '--disable-warning=ExperimentalWarning --disable-warning=DeprecationWarning'
jobs:
bundle-size:
name: Bundle Size
runs-on: ${{ vars.DEPOT_ENABLED == 'true' && 'depot-ubuntu-latest' || 'ubuntu-latest' }}
permissions:
actions: write
pull-requests: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
submodules: "recursive"
persist-credentials: false
- name: Install dependencies
uses: ./.github/actions/install-dependencies
- name: Generate Worker types
run: pnpm gen:types
working-directory: apps/explorer
- name: Restore baseline from cache
if: github.event_name == 'pull_request'
id: cache-restore
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7
with:
path: apps/explorer/bundle-stats.json
key: bundle-stats-explorer-main-latest
restore-keys: |
bundle-stats-explorer-main-
- name: Move baseline if exists
if: github.event_name == 'pull_request' && steps.cache-restore.outputs.cache-hit == 'true'
run: mv apps/explorer/bundle-stats.json apps/explorer/baseline-stats.json
- name: Build with bundle analysis
working-directory: apps/explorer
env:
ANALYZE: "true"
ANALYZE_JSON: "true"
run: pnpm build
- name: Parse bundle stats (main branch)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
working-directory: apps/explorer
run: |
node --experimental-strip-types scripts/bundle-diff.ts \
--skip-build \
--output bundle-stats.json
- name: Save bundle stats to cache (main branch)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7
with:
path: apps/explorer/bundle-stats.json
key: bundle-stats-explorer-main-${{ github.sha }}
- name: Delete old latest cache (main branch)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh cache delete bundle-stats-explorer-main-latest --repo ${{ github.repository }}
- name: Save bundle stats with stable key (main branch)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/cache/save@668228422ae6a00e4ad889ee87cd7109ec5666a7
with:
path: apps/explorer/bundle-stats.json
key: bundle-stats-explorer-main-latest
- name: Generate bundle report (PR)
if: github.event_name == 'pull_request'
id: bundle-report
working-directory: apps/explorer
run: |
if [ -f baseline-stats.json ]; then
REPORT=$(node --experimental-strip-types scripts/bundle-diff.ts \
--ci \
--skip-build \
--baseline baseline-stats.json)
else
REPORT=$(node --experimental-strip-types scripts/bundle-diff.ts \
--ci \
--skip-build)
fi
# Write to file for the comment action
echo "$REPORT" > bundle-report.md
# Also output for debugging
echo "$REPORT"
- name: Find existing comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "Bundle Size Report"
- name: Post or update PR comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body-path: apps/explorer/bundle-report.md
edit-mode: replace
- name: Upload Sonda report artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: sonda-bundle-report-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || format('main-{0}', github.sha) }}
path: apps/explorer/.sonda/
retention-days: 90
- name: Deploy to GitHub Pages (main only)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./apps/explorer/.sonda
destination_dir: explorer-bundle-stats
keep_files: false