-
-
Notifications
You must be signed in to change notification settings - Fork 3
186 lines (158 loc) · 8.03 KB
/
bundle-analysis.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: "Bundle Analysis"
on: # yamllint disable-line rule:truthy
pull_request: # yamllint disable-line rule:empty-values
push:
branches:
- "main"
defaults:
run:
working-directory: "./"
permissions:
contents: "read" # to fetch code (actions/checkout)
pull-requests: "write"
concurrency:
group: "ci-bundle-analysis-${{ github.ref }}-1"
cancel-in-progress: true
jobs:
files-changed:
name: "Detect what files changed"
runs-on: "ubuntu-22.04"
timeout-minutes: 3
# Map a step output to a job output
outputs:
nextra: "${{ steps.changes.outputs.nextra }}"
steps:
- name: "Harden Runner"
uses: "step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6" # v2.8.1
with:
egress-policy: "audit"
- name: "Git checkout"
uses: "actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29" # v4.1.6
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- name: "Check for file changes"
uses: "dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36" # v3.0.2
id: "changes"
with:
token: "${{ github.token }}"
filters: ".github/file-filters.yml"
nextra-analyze-bundle:
if: "needs.files-changed.outputs.nextra == 'true'"
needs: "files-changed"
name: "Analyze Bundle (nextra)"
runs-on: "ubuntu-latest"
steps:
- name: "Harden Runner"
uses: "step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6" # v2.8.1
with:
egress-policy: "audit"
- name: "Git checkout"
uses: "actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29" # v4.1.6
env:
GIT_COMMITTER_NAME: "GitHub Actions Shell"
GIT_AUTHOR_NAME: "GitHub Actions Shell"
EMAIL: "github-actions[bot]@users.noreply.github.com"
- uses: "pnpm/action-setup@a3252b78c470c02df07e9d59298aecedc3ccdd6d" # v3.0.0
- name: "Set node version to 18"
uses: "actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8" # v4.0.2
with:
node-version: "18"
cache: "pnpm"
- name: "Verify the integrity of provenance attestations and registry signatures for installed dependencies"
run: "pnpm dlx audit-ci@^7 --config ./audit-ci.jsonc --report-type=summary"
- name: "Install packages"
run: "pnpm install --frozen-lockfile --prefer-offline"
env:
SKIP_CHECK: "true"
"PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD": 1
- name: "Restore Next.js Build"
uses: "actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9" # v4.0.2
id: "restore-build-cache"
env:
cache-name: "cache-next-build"
with:
# if you use a custom build directory, replace all instances of `.next` in this file with your build directory
# ex: if your app builds to `dist`, replace `.next` with `dist`
path: "examples/nextra/.next/cache"
# change this if you prefer a more strict cache
key: "${{ runner.os }}-build-${{ env.cache-name }}"
- name: "Build @visulima/nextra-theme-docs"
run: "pnpm run build:nextra-theme-docs:prod"
- name: "Build Next.js App"
# change this if your site requires a custom build command
run: "cd examples/nextra && ./node_modules/.bin/next build"
# Here's the first place where next-bundle-analysis' own script is used
# This step pulls the raw bundle stats for the current bundle
- name: "Analyze Bundle"
run: "cd examples/nextra && npx -p nextjs-bundle-analysis@0.5.0 report"
- name: "Upload Bundle"
uses: "actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808" # v4.3.3
with:
name: "bundle"
path: "examples/nextra/.next/analyze/__bundle_analysis.json"
- name: "Download Base Branch Bundle Stats"
uses: "dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe" # v3.1.4
if: "success() && github.event.number"
with:
workflow: "nextjs-bundle-analysis.yml"
branch: "${{ github.event.pull_request.base.ref }}"
path: "examples/nextra/.next/analyze/base"
# And here's the second place - this runs after we have both the current and
# base branch bundle stats, and will compare them to determine what changed.
# There are two configurable arguments that come from package.json:
#
# - budget: optional, set a budget (bytes) against which size changes are measured
# it's set to 350kb here by default, as informed by the following piece:
# https://infrequently.org/2021/03/the-performance-inequality-gap/
#
# - red-status-percentage: sets the percent size increase where you get a red
# status indicator, defaults to 20%
#
# Either of these arguments can be changed or removed by editing the `nextBundleAnalysis`
# entry in your package.json file.
- name: "Compare With Base Branch Bundle"
if: "success() && github.event.number"
run: "ls -laR examples/nextra/.next/analyze/base && cd examples/nextra && npx -p nextjs-bundle-analysis@0.5.0 compare"
- name: "Get Comment body"
id: "get-comment-body"
if: "success() && github.event.number"
run: |
echo 'body<<EOF' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
echo '## Size changes' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
echo '<details>' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
cat examples/nextra/.next/analyze/__bundle_analysis_comment.txt >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
echo '</details>' >> $GITHUB_OUTPUT
echo '' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: "Comment"
uses: "marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31" # v2.9.0
if: "success() && github.event.number"
with:
header: "next-bundle-analysis"
message: "${{ steps.get-comment-body.outputs.body }}"
# This check runs once all dependant jobs have passed
# It symbolizes that all required checks have successfully passed (Or skipped)
# This check is the only required GitHub check
test-required-check:
needs: ["files-changed", "nextra-analyze-bundle"]
name: "Check Bundle Analysis Run"
# This is necessary since a failed/skipped dependent job would cause this job to be skipped
if: "always()"
runs-on: "ubuntu-22.04"
steps:
# If any jobs we depend on fail, we will fail since this is a required check
# NOTE: A timeout is considered a failure
- name: "Harden Runner"
uses: "step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6" # v2.8.1
with:
egress-policy: "audit"
- name: "Check for failures"
if: "contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')"
run: |
echo "One of the dependent jobs have failed. You may need to re-run it." && exit 1