Repository navigation
410 lines (366 loc) · 17.9 KB
/
Copy pathbundle-analysis.yml
File metadata and controls
410 lines (366 loc) · 17.9 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
name: Bundle Analysis
on:
workflow_dispatch:
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
paths:
- ".github/workflows/bundle-analysis.yml"
- "e2e/fixtures/agent-tools-sandbox/**"
- "apps/fixtures/weather-agent/**"
- "package.json"
- "packages/eve/**"
- "pnpm-lock.yaml"
- "pnpm-workspace.yaml"
- "scripts/init-install-report.mjs"
- "scripts/build-profile-report.mjs"
- "scripts/nitro-bundle-report-compare.mjs"
- "scripts/nitro-bundle-report-budget.mjs"
- "scripts/nitro-bundle-report.mjs"
- "scripts/package-publish-report.mjs"
concurrency:
group: weather-agent-bundle-analysis-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
analyze:
if: ${{ github.event_name != 'pull_request' || (github.event.pull_request.head.repo.fork == false && (github.event.action != 'labeled' || github.event.label.name == 'acknowledge-bundle-warning')) }}
permissions:
contents: read
issues: write
pull-requests: write
runs-on: ubuntu-latest
env:
BUNDLE_WARNING_ACK_LABEL: acknowledge-bundle-warning
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_USE_EXPERIMENTAL_FRAMEWORKS: "1"
steps:
- name: Resolve workflow mode
id: mode
env:
EVENT_ACTION: ${{ github.event.action }}
EVENT_LABEL_NAME: ${{ github.event.label.name }}
PR_HAS_ACK_LABEL: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'acknowledge-bundle-warning') }}
run: |
if [ "$EVENT_ACTION" = "labeled" ] && [ "$EVENT_LABEL_NAME" = "$BUNDLE_WARNING_ACK_LABEL" ]; then
echo "acknowledge_only=true" >> "$GITHUB_OUTPUT"
echo "acknowledged=true" >> "$GITHUB_OUTPUT"
echo "Bundle warning acknowledged by label; skipping regeneration." >> "$GITHUB_STEP_SUMMARY"
else
echo "acknowledge_only=false" >> "$GITHUB_OUTPUT"
if [ "$EVENT_ACTION" != "synchronize" ] && [ "$PR_HAS_ACK_LABEL" = "true" ]; then
echo "acknowledged=true" >> "$GITHUB_OUTPUT"
else
echo "acknowledged=false" >> "$GITHUB_OUTPUT"
fi
fi
- name: Clear stale bundle warning acknowledgement
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' && github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'acknowledge-bundle-warning') }}
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
try {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
name: process.env.BUNDLE_WARNING_ACK_LABEL,
owner: context.repo.owner,
repo: context.repo.repo,
});
} catch (error) {
if (error.status === 404) {
return;
}
throw error;
}
await core.summary
.addRaw(
`Removed \`${process.env.BUNDLE_WARNING_ACK_LABEL}\` so this commit must be acknowledged separately.`,
)
.write();
- name: Checkout code
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Setup pnpm
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- name: Setup Node.js
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
cache: "pnpm"
- name: Install Vercel CLI
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
run: pnpm add --global vercel@latest && vercel --version
- name: Resolve eve sandbox image
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
uses: ./.github/actions/sandbox-image
- name: Install dependencies
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
run: pnpm install --frozen-lockfile
- name: Prepare pull request base worktree
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' }}
id: baseline
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
BASELINE_ROOT="$RUNNER_TEMP/eve-pr-base"
rm -rf "$BASELINE_ROOT"
git worktree add --detach "$BASELINE_ROOT" "$BASE_SHA"
echo "root=$BASELINE_ROOT" >> "$GITHUB_OUTPUT"
echo "label=${BASE_REF} (${BASE_SHA:0:7})" >> "$GITHUB_OUTPUT"
- name: Install pull request base dependencies
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' }}
working-directory: ${{ steps.baseline.outputs.root }}
run: pnpm install --frozen-lockfile
- name: Build eve package on pull request base
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' }}
working-directory: ${{ steps.baseline.outputs.root }}
run: pnpm --filter eve build
- name: Resolve weather app on pull request base
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' }}
id: baseline_weather_app
working-directory: ${{ steps.baseline.outputs.root }}
run: |
if [ -d apps/fixtures/weather-agent ]; then
echo "filter=weather-agent" >> "$GITHUB_OUTPUT"
echo "path=apps/fixtures/weather-agent" >> "$GITHUB_OUTPUT"
elif [ -d apps/fixtures/weather-fixture ]; then
echo "filter=weather-fixture" >> "$GITHUB_OUTPUT"
echo "path=apps/fixtures/weather-fixture" >> "$GITHUB_OUTPUT"
elif [ -d apps/weather-agent ]; then
echo "filter=weather-agent" >> "$GITHUB_OUTPUT"
echo "path=apps/weather-agent" >> "$GITHUB_OUTPUT"
else
echo "Could not find weather app in baseline checkout." >&2
exit 1
fi
- name: Build weather app on pull request base for size analysis
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' }}
id: baseline_build
continue-on-error: true
working-directory: ${{ steps.baseline.outputs.root }}
env:
STEPS_BASELINE_WEATHER_APP_OUTPUTS_FILTER: ${{ steps.baseline_weather_app.outputs.filter }}
run: >-
VERCEL=1 pnpm --filter "${STEPS_BASELINE_WEATHER_APP_OUTPUTS_FILTER}" \
exec eve build --skip-sandbox-prewarm
- name: Note skipped pull request base size analysis
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' && steps.baseline_build.outcome != 'success' }}
run: |
echo "Pull request base build failed; bundle analysis will run without a baseline comparison." >> "$GITHUB_STEP_SUMMARY"
- name: Generate pull request base bundle report
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' && steps.baseline_build.outcome == 'success' }}
env:
BASELINE_REPORT_JSON: ${{ runner.temp }}/weather-agent-bundle-report-base.json
STEPS_BASELINE_WEATHER_APP_OUTPUTS_PATH: ${{ steps.baseline_weather_app.outputs.path }}
working-directory: ${{ steps.baseline.outputs.root }}
run: |
node ./scripts/nitro-bundle-report.mjs \
--app "${STEPS_BASELINE_WEATHER_APP_OUTPUTS_PATH}" \
--app-label apps/fixtures/weather-agent \
--package packages/eve \
--package-label packages/eve \
--output-json "$BASELINE_REPORT_JSON"
- name: Build sandbox benchmark on pull request base in Vercel mode
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' }}
id: baseline_sandbox_build
continue-on-error: true
working-directory: ${{ steps.baseline.outputs.root }}
env:
BASELINE_SANDBOX_BUILD_PROFILE: ${{ runner.temp }}/sandbox-build-profile-base.json
run: |
token_args=()
if [ -n "${VERCEL_TOKEN:-}" ]; then
token_args=(--token "$VERCEL_TOKEN")
fi
team_args=()
if [ -n "${VERCEL_ORG_ID:-}" ]; then
team_args=(--team "$VERCEL_ORG_ID")
fi
pnpm --filter agent-tools-sandbox exec vercel link --yes \
--project "$VERCEL_PROJECT_ID" "${team_args[@]}" "${token_args[@]}"
pnpm --filter agent-tools-sandbox exec vercel env pull --yes --environment=preview \
"${token_args[@]}"
profile_args=()
if pnpm --filter agent-tools-sandbox exec eve build --help | grep -Fq -- "--profile"; then
profile_args=(--profile "$BASELINE_SANDBOX_BUILD_PROFILE")
else
echo "Pull request base predates eve build --profile; build timing will report the current build only." >> "$GITHUB_STEP_SUMMARY"
fi
# Sandbox templates key on VERCEL_PROJECT_ID at build and runtime.
# Do not add VERCEL_TEAM_ID: runtime does not receive it.
VERCEL=1 \
VERCEL_ENV=preview \
VERCEL_TARGET_ENV=preview \
VERCEL_PROJECT_ID="$VERCEL_PROJECT_ID" \
pnpm --filter agent-tools-sandbox exec eve build "${profile_args[@]}"
- name: Note skipped sandbox benchmark base
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' && steps.baseline_sandbox_build.outcome != 'success' }}
run: |
echo "Pull request base sandbox benchmark failed; build timing will run without a baseline comparison." >> "$GITHUB_STEP_SUMMARY"
- name: Build eve package
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
run: pnpm --filter eve build
- name: Build weather-agent for size analysis
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
run: >-
VERCEL=1 pnpm --filter weather-agent
exec eve build --skip-sandbox-prewarm
- name: Build sandbox benchmark in Vercel mode
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
env:
SANDBOX_BUILD_PROFILE: ${{ runner.temp }}/sandbox-build-profile.json
run: |
token_args=()
if [ -n "${VERCEL_TOKEN:-}" ]; then
token_args=(--token "$VERCEL_TOKEN")
fi
team_args=()
if [ -n "${VERCEL_ORG_ID:-}" ]; then
team_args=(--team "$VERCEL_ORG_ID")
fi
pnpm --filter agent-tools-sandbox exec vercel link --yes \
--project "$VERCEL_PROJECT_ID" "${team_args[@]}" "${token_args[@]}"
pnpm --filter agent-tools-sandbox exec vercel env pull --yes --environment=preview \
"${token_args[@]}"
# Sandbox templates key on VERCEL_PROJECT_ID at build and runtime.
# Do not add VERCEL_TEAM_ID: runtime does not receive it.
VERCEL=1 \
VERCEL_ENV=preview \
VERCEL_TARGET_ENV=preview \
VERCEL_PROJECT_ID="$VERCEL_PROJECT_ID" \
pnpm --filter agent-tools-sandbox exec eve build --profile "$SANDBOX_BUILD_PROFILE"
- name: Generate bundle report
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
env:
BASELINE_REPORT_JSON: ${{ runner.temp }}/weather-agent-bundle-report-base.json
BASELINE_REPORT_LABEL: ${{ steps.baseline.outputs.label }}
HAS_BASELINE_REPORT: ${{ github.event_name == 'pull_request' && steps.baseline_build.outcome == 'success' }}
BUNDLE_REPORT_JSON: ${{ runner.temp }}/weather-agent-bundle-report.json
BUNDLE_REPORT_MARKDOWN: ${{ runner.temp }}/weather-agent-bundle-report.md
BUNDLE_WARNING_ACKNOWLEDGED: ${{ steps.mode.outputs.acknowledged }}
run: |
report_args=()
if [ "$HAS_BASELINE_REPORT" = "true" ]; then
report_args=(
--baseline-json "$BASELINE_REPORT_JSON"
--baseline-label "$BASELINE_REPORT_LABEL"
)
fi
if [ "$BUNDLE_WARNING_ACKNOWLEDGED" = "true" ]; then
report_args+=(--size-budget-acknowledged)
fi
node ./scripts/nitro-bundle-report.mjs \
--app apps/fixtures/weather-agent \
--app-label apps/fixtures/weather-agent \
--package packages/eve \
--package-label packages/eve \
"${report_args[@]}" \
--output-json "$BUNDLE_REPORT_JSON" \
--output-markdown "$BUNDLE_REPORT_MARKDOWN"
- name: Generate build timing report
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
env:
BASELINE_BUILD_PROFILE: ${{ runner.temp }}/sandbox-build-profile-base.json
BASELINE_BUILD_PROFILE_LABEL: ${{ steps.baseline.outputs.label }}
BUILD_PROFILE: ${{ runner.temp }}/sandbox-build-profile.json
BUILD_PROFILE_REPORT_JSON: ${{ runner.temp }}/sandbox-build-profile-report.json
BUILD_PROFILE_REPORT_MARKDOWN: ${{ runner.temp }}/sandbox-build-profile-report.md
HAS_BASELINE_BUILD_PROFILE: ${{ github.event_name == 'pull_request' && steps.baseline_sandbox_build.outcome == 'success' }}
run: |
report_args=()
if [ "$HAS_BASELINE_BUILD_PROFILE" = "true" ] && [ -f "$BASELINE_BUILD_PROFILE" ]; then
report_args=(
--baseline-profile "$BASELINE_BUILD_PROFILE"
--baseline-label "$BASELINE_BUILD_PROFILE_LABEL"
)
fi
node ./scripts/build-profile-report.mjs \
--profile "$BUILD_PROFILE" \
--app-label e2e/fixtures/agent-tools-sandbox \
--sandbox-prewarm included \
--require-phase sandbox.prewarm \
"${report_args[@]}" \
--output-json "$BUILD_PROFILE_REPORT_JSON" \
--output-markdown "$BUILD_PROFILE_REPORT_MARKDOWN"
- name: Combine bundle and timing reports
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
env:
ANALYSIS_REPORT_MARKDOWN: ${{ runner.temp }}/weather-agent-analysis-report.md
BUILD_PROFILE_REPORT_MARKDOWN: ${{ runner.temp }}/sandbox-build-profile-report.md
BUNDLE_REPORT_MARKDOWN: ${{ runner.temp }}/weather-agent-bundle-report.md
run: |
cat "$BUNDLE_REPORT_MARKDOWN" > "$ANALYSIS_REPORT_MARKDOWN"
printf '\n\n' >> "$ANALYSIS_REPORT_MARKDOWN"
cat "$BUILD_PROFILE_REPORT_MARKDOWN" >> "$ANALYSIS_REPORT_MARKDOWN"
- name: Publish job summary
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
env:
ANALYSIS_REPORT_MARKDOWN: ${{ runner.temp }}/weather-agent-analysis-report.md
run: cat "$ANALYSIS_REPORT_MARKDOWN" >> "$GITHUB_STEP_SUMMARY"
- name: Upload bundle report artifact
if: ${{ steps.mode.outputs.acknowledge_only != 'true' }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: weather-agent-bundle-report
path: |
${{ runner.temp }}/weather-agent-bundle-report.json
${{ runner.temp }}/weather-agent-bundle-report.md
${{ runner.temp }}/sandbox-build-profile*.json
${{ runner.temp }}/sandbox-build-profile*.md
${{ runner.temp }}/weather-agent-analysis-report.md
- name: Update pull request comment
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' }}
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
ANALYSIS_REPORT_MARKDOWN: ${{ runner.temp }}/weather-agent-analysis-report.md
with:
script: |
const fs = require("node:fs");
const marker = "<!-- eve-weather-agent-bundle-analysis -->";
const reportBody = fs.readFileSync(process.env.ANALYSIS_REPORT_MARKDOWN, "utf8").trim();
const body = `${marker}\n${reportBody}`;
const comments = await github.paginate(github.rest.issues.listComments, {
issue_number: context.issue.number,
owner: context.repo.owner,
per_page: 100,
repo: context.repo.repo,
});
const existingComment = comments.find(
(comment) => comment.user?.type === "Bot" && comment.body?.includes(marker),
);
if (existingComment) {
await github.rest.issues.updateComment({
body,
comment_id: existingComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
});
return;
}
await github.rest.issues.createComment({
body,
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
- name: Enforce bundle size budget
if: ${{ steps.mode.outputs.acknowledge_only != 'true' && github.event_name == 'pull_request' }}
env:
BUNDLE_REPORT_JSON: ${{ runner.temp }}/weather-agent-bundle-report.json
BUNDLE_WARNING_ACKNOWLEDGED: ${{ steps.mode.outputs.acknowledged }}
run: |
budget_args=(--report-json "$BUNDLE_REPORT_JSON")
if [ "$BUNDLE_WARNING_ACKNOWLEDGED" = "true" ]; then
budget_args+=(--acknowledged)
fi
node ./scripts/nitro-bundle-report-budget.mjs "${budget_args[@]}"