forked from vercel/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
613 lines (527 loc) · 21.8 KB
/
benchmarks.yml
File metadata and controls
613 lines (527 loc) · 21.8 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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
name: Performance Benchmarks
on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch: # Allow manual triggers
inputs:
full_suite:
description: 'Run full benchmark suite (includes long-running 100+ step benchmarks)'
required: false
type: boolean
default: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Phase 0: Update PR comment to show benchmarks are running
pr-comment-start:
name: Create PR Comment
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
timeout-minutes: 2
steps:
- name: Find existing benchmark comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- benchmark-results -->'
- name: Get existing comment body
if: steps.find-comment.outputs.comment-id != ''
id: get-comment
uses: actions/github-script@v7
with:
script: |
const comment = await github.rest.issues.getComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.find-comment.outputs.comment-id }}
});
// Extract the results section (everything after the header and running message)
const body = comment.data.body;
// Remove any existing stale warning and running message
let resultsSection = body
.replace(/<!-- benchmark-results -->\n## 📊 Benchmark Results\n\n> ⚠️ \*\*Results below are stale\*\*[^\n]*\n\n/g, '')
.replace(/<!-- benchmark-results -->\n## 📊 Benchmark Results\n\n/g, '')
.replace(/⏳ \*\*Benchmarks are running\.\.\.\*\*\n\n---\n_Started at:[^_]*_\n\n---\n\n/g, '')
.replace(/⏳ \*\*Benchmarks are running\.\.\.\*\*\n\n---\n_Started at:[^_]*_/g, '')
.trim();
// If there's actual content left (benchmark tables), save it
if (resultsSection && resultsSection.includes('|')) {
core.setOutput('has-results', 'true');
core.setOutput('previous-results', resultsSection);
} else {
core.setOutput('has-results', 'false');
}
- name: Create new benchmark comment
if: steps.find-comment.outputs.comment-id == ''
uses: marocchino/sticky-pull-request-comment@v2
with:
header: benchmark-results
message: |
<!-- benchmark-results -->
## 📊 Benchmark Results
⏳ **Benchmarks are running...**
This comment will be updated with the results when the benchmarks complete.
---
_Started at: ${{ github.event.pull_request.updated_at }}_
- name: Update existing benchmark comment with stale warning
if: steps.find-comment.outputs.comment-id != '' && steps.get-comment.outputs.has-results == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: benchmark-results
message: |
<!-- benchmark-results -->
## 📊 Benchmark Results
> ⚠️ **Results below are stale** and not from the latest commit. This comment will be updated when CI completes on the latest run.
⏳ **Benchmarks are running...**
---
_Started at: ${{ github.event.pull_request.updated_at }}_
---
${{ steps.get-comment.outputs.previous-results }}
- name: Update existing benchmark comment without results
if: steps.find-comment.outputs.comment-id != '' && steps.get-comment.outputs.has-results != 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: benchmark-results
message: |
<!-- benchmark-results -->
## 📊 Benchmark Results
⏳ **Benchmarks are running...**
This comment will be updated with the results when the benchmarks complete.
---
_Started at: ${{ github.event.pull_request.updated_at }}_
# Phase 1: Build all packages (not workbenches)
build:
name: Build Packages
runs-on: ubuntu-latest
timeout-minutes: 30
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
steps:
- uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/setup-workflow-dev
with:
build-packages: 'true'
# Cache node_modules and package build outputs
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
node_modules
packages/*/dist
packages/core/src/version.ts
retention-days: 1
# Phase 2a: Local benchmarks (no postgres)
benchmark-local:
name: Benchmark Local (${{ matrix.app }})
runs-on: ubuntu-latest
needs: build
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
# Note: Use actual directory names, not symlinks (nitro -> nitro-v3)
app: [nextjs-turbopack, nitro-v3, express]
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
WORKFLOW_PUBLIC_MANIFEST: '1'
steps:
- uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/setup-workflow-dev
with:
install-dependencies: 'false'
build-packages: 'false'
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: .
- name: Install dependencies
run: pnpm install --frozen-lockfile
# For PRs, download baseline results from the PR's base branch
- name: Download baseline from PR base branch
if: github.event_name == 'pull_request'
continue-on-error: true
uses: dawidd6/action-download-artifact@v6
with:
workflow: benchmarks.yml
branch: ${{ github.event.pull_request.base.ref }}
name: baseline-benchmark-results
path: baseline-results
if_no_artifact_found: warn
- name: Build workbench
run: pnpm turbo run build --filter='./workbench/${{ matrix.app }}'
- name: Run benchmarks
env:
DEPLOYMENT_URL: "http://localhost:3000"
APP_NAME: ${{ matrix.app }}
# Run full suite only when manually triggered with full_suite=true
BENCHMARK_FULL_SUITE: ${{ github.event_name == 'workflow_dispatch' && inputs.full_suite }}
run: |
cd workbench/${{ matrix.app }}
pnpm start &
echo "Waiting for server to start..."
sleep 15
cd ../..
pnpm vitest bench packages/core/e2e/bench.bench.ts --run --outputJson=bench-results-${{ matrix.app }}-local.json
- name: Render benchmark results
uses: ./.github/actions/render-benchmarks
with:
benchmark-file: bench-results-${{ matrix.app }}-local.json
app-name: ${{ matrix.app }}
backend: local
baseline-file: baseline-results/bench-results-${{ matrix.app }}-local.json
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: bench-results-${{ matrix.app }}-local
path: |
bench-results-${{ matrix.app }}-local.json
bench-timings-${{ matrix.app }}-local.json
# Phase 2b: Postgres benchmarks (with postgres service)
benchmark-postgres:
name: Benchmark Postgres (${{ matrix.app }})
runs-on: ubuntu-latest
needs: build
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
# Note: Use actual directory names, not symlinks (nitro -> nitro-v3)
app: [nextjs-turbopack, nitro-v3, express]
services:
postgres:
image: postgres:18-alpine
env:
POSTGRES_USER: world
POSTGRES_PASSWORD: world
POSTGRES_DB: world
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
WORKFLOW_PUBLIC_MANIFEST: '1'
WORKFLOW_TARGET_WORLD: "@workflow/world-postgres"
WORKFLOW_POSTGRES_URL: "postgres://world:world@localhost:5432/world"
steps:
- uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/setup-workflow-dev
with:
install-dependencies: 'false'
build-packages: 'false'
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: .
- name: Install dependencies
run: pnpm install --frozen-lockfile
# For PRs, download baseline results from the PR's base branch
- name: Download baseline from PR base branch
if: github.event_name == 'pull_request'
continue-on-error: true
uses: dawidd6/action-download-artifact@v6
with:
workflow: benchmarks.yml
branch: ${{ github.event.pull_request.base.ref }}
name: baseline-benchmark-results
path: baseline-results
if_no_artifact_found: warn
- name: Setup PostgreSQL database
run: ./packages/world-postgres/bin/setup.js
# Build workbench with postgres world (build output differs based on target world)
- name: Build workbench for postgres
run: pnpm turbo run build --filter='./workbench/${{ matrix.app }}'
- name: Run benchmarks
env:
DEPLOYMENT_URL: "http://localhost:3000"
APP_NAME: ${{ matrix.app }}
# Run full suite only when manually triggered with full_suite=true
BENCHMARK_FULL_SUITE: ${{ github.event_name == 'workflow_dispatch' && inputs.full_suite }}
run: |
cd workbench/${{ matrix.app }}
pnpm start &
echo "Waiting for server to start..."
sleep 15
cd ../..
pnpm vitest bench packages/core/e2e/bench.bench.ts --run --outputJson=bench-results-${{ matrix.app }}-postgres.json
- name: Render benchmark results
uses: ./.github/actions/render-benchmarks
with:
benchmark-file: bench-results-${{ matrix.app }}-postgres.json
app-name: ${{ matrix.app }}
backend: postgres
baseline-file: baseline-results/bench-results-${{ matrix.app }}-postgres.json
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: bench-results-${{ matrix.app }}-postgres
path: |
bench-results-${{ matrix.app }}-postgres.json
bench-timings-${{ matrix.app }}-postgres.json
# Phase 2c: Vercel benchmarks (needs build artifacts for packages)
benchmark-vercel:
name: Benchmark Vercel (${{ matrix.app.name }})
runs-on: ubuntu-latest
needs: build
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
app:
- name: "nextjs-turbopack"
project-id: "prj_yjkM7UdHliv8bfxZ1sMJQf1pMpdi"
project-slug: "example-nextjs-workflow-turbopack"
- name: "nitro-v3"
project-id: "prj_e7DZirYdLrQKXNrlxg7KmA6ABx8r"
project-slug: "workbench-nitro-workflow"
- name: "express"
project-id: "prj_cCZjpBy92VRbKHHbarDMhOHtkuIr"
project-slug: "workbench-express-workflow"
steps:
- uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/setup-workflow-dev
with:
install-dependencies: 'false'
build-packages: 'false'
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: .
- name: Install dependencies
run: pnpm install --frozen-lockfile
# For PRs, download baseline results from the PR's base branch
- name: Download baseline from PR base branch
if: github.event_name == 'pull_request'
continue-on-error: true
uses: dawidd6/action-download-artifact@v6
with:
workflow: benchmarks.yml
branch: ${{ github.event.pull_request.base.ref }}
name: baseline-benchmark-results
path: baseline-results
if_no_artifact_found: warn
- name: Wait for Vercel deployment
id: waitForDeployment
uses: ./.github/actions/wait-for-vercel-project
with:
team-id: "team_nO2mCG4W8IxPIeKoSsqwAxxB"
project-id: ${{ matrix.app.project-id }}
vercel-token: ${{ secrets.VERCEL_LABS_TOKEN }}
timeout: 1000
check-interval: 15
environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
- name: Run benchmarks
env:
DEPLOYMENT_URL: ${{ steps.waitForDeployment.outputs.deployment-url }}
APP_NAME: ${{ matrix.app.name }}
VERCEL_DEPLOYMENT_ID: ${{ steps.waitForDeployment.outputs.deployment-id }}
WORKFLOW_VERCEL_ENV: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
WORKFLOW_VERCEL_AUTH_TOKEN: ${{ secrets.VERCEL_LABS_TOKEN }}
WORKFLOW_VERCEL_TEAM: "team_nO2mCG4W8IxPIeKoSsqwAxxB"
WORKFLOW_VERCEL_PROJECT: ${{ matrix.app.project-id }}
WORKFLOW_VERCEL_PROJECT_SLUG: ${{ matrix.app.project-slug }}
VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
# Run full suite only when manually triggered with full_suite=true
BENCHMARK_FULL_SUITE: ${{ github.event_name == 'workflow_dispatch' && inputs.full_suite }}
run: |
pnpm vitest bench packages/core/e2e/bench.bench.ts --run --outputJson=bench-results-${{ matrix.app.name }}-vercel.json
- name: Render benchmark results
uses: ./.github/actions/render-benchmarks
with:
benchmark-file: bench-results-${{ matrix.app.name }}-vercel.json
app-name: ${{ matrix.app.name }}
backend: vercel
baseline-file: baseline-results/bench-results-${{ matrix.app.name }}-vercel.json
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
name: bench-results-${{ matrix.app.name }}-vercel
path: |
bench-results-${{ matrix.app.name }}-vercel.json
bench-timings-${{ matrix.app.name }}-vercel.json
# Phase 2d: Community World benchmarks (dynamically generated from worlds-manifest.json)
getCommunityWorldsMatrix:
name: Get Community Worlds Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/setup-workflow-dev
with:
install-dependencies: 'false'
build-packages: 'false'
- id: set-matrix
run: echo "matrix=$(node ./scripts/create-community-worlds-matrix.mjs)" >> $GITHUB_OUTPUT
benchmark-community:
name: Benchmark Community World (${{ matrix.world.name }})
needs: [build, getCommunityWorldsMatrix]
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.getCommunityWorldsMatrix.outputs.matrix) }}
uses: ./.github/workflows/benchmark-community-world.yml
with:
world-id: ${{ matrix.world.id }}
world-name: ${{ matrix.world.name }}
world-package: ${{ matrix.world.package }}
service-type: ${{ matrix.world.service-type }}
env-vars: ${{ matrix.world.env-vars }}
setup-command: ${{ matrix.world.setup-command }}
# Run full suite only when manually triggered with full_suite=true
full-suite: ${{ github.event_name == 'workflow_dispatch' && inputs.full_suite }}
secrets: inherit
# Phase 3: Aggregate all benchmark results and create comparison
summary:
name: Benchmark Summary
runs-on: ubuntu-latest
needs: [benchmark-local, benchmark-postgres, benchmark-vercel, benchmark-community]
if: always() && !cancelled()
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Download all benchmark artifacts
uses: actions/download-artifact@v4
with:
pattern: bench-results-*
path: benchmark-results
merge-multiple: true
- name: List downloaded files
run: find benchmark-results -type f -name "*.json" | sort
# For PRs, download baseline results from the PR's base branch
- name: Download baseline from PR base branch
if: github.event_name == 'pull_request'
continue-on-error: true
uses: dawidd6/action-download-artifact@v6
with:
workflow: benchmarks.yml
branch: ${{ github.event.pull_request.base.ref }}
name: baseline-benchmark-results
path: baseline-results
if_no_artifact_found: warn
- name: Aggregate and compare benchmarks
id: aggregate
run: |
# Check if baseline results exist
BASELINE_ARG=""
if [ -d "baseline-results" ] && [ "$(ls -A baseline-results 2>/dev/null)" ]; then
echo "Found baseline results from main branch"
BASELINE_ARG="--baseline baseline-results"
else
echo "No baseline results found, showing results without comparison"
fi
# Capture output to both file and step summary
node .github/scripts/aggregate-benchmarks.js benchmark-results $BASELINE_ARG --run-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | tee benchmark-summary.md >> $GITHUB_STEP_SUMMARY
- name: Check benchmark job statuses
id: check-status
run: |
# Check if any benchmark jobs failed
LOCAL_STATUS="${{ needs.benchmark-local.result }}"
POSTGRES_STATUS="${{ needs.benchmark-postgres.result }}"
VERCEL_STATUS="${{ needs.benchmark-vercel.result }}"
COMMUNITY_STATUS="${{ needs.benchmark-community.result }}"
echo "local=$LOCAL_STATUS" >> $GITHUB_OUTPUT
echo "postgres=$POSTGRES_STATUS" >> $GITHUB_OUTPUT
echo "vercel=$VERCEL_STATUS" >> $GITHUB_OUTPUT
echo "community=$COMMUNITY_STATUS" >> $GITHUB_OUTPUT
# Community world failures are warnings, not errors
if [[ "$LOCAL_STATUS" == "failure" || "$POSTGRES_STATUS" == "failure" || "$VERCEL_STATUS" == "failure" ]]; then
echo "has_failures=true" >> $GITHUB_OUTPUT
else
echo "has_failures=false" >> $GITHUB_OUTPUT
fi
if [[ "$COMMUNITY_STATUS" == "failure" ]]; then
echo "has_warnings=true" >> $GITHUB_OUTPUT
else
echo "has_warnings=false" >> $GITHUB_OUTPUT
fi
- name: Update PR comment with results
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: benchmark-results
path: benchmark-summary.md
- name: Append failure notice to PR comment
if: github.event_name == 'pull_request' && steps.check-status.outputs.has_failures == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: benchmark-results
append: true
message: |
---
❌ **Some benchmark jobs failed:**
- Local: ${{ needs.benchmark-local.result }}
- Postgres: ${{ needs.benchmark-postgres.result }}
- Vercel: ${{ needs.benchmark-vercel.result }}
Check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
- name: Append community warning to PR comment
if: github.event_name == 'pull_request' && steps.check-status.outputs.has_warnings == 'true'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: benchmark-results
append: true
message: |
---
⚠️ **Community world benchmarks failed** (non-blocking):
- Community Worlds: ${{ needs.benchmark-community.result }}
Check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.
# On main branch, save results as baseline for future PR comparisons
- name: Upload baseline results
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: baseline-benchmark-results
path: benchmark-results/
retention-days: 90
# Publish benchmark results to GitHub Pages (main branch only)
publish-results:
name: Publish Benchmark Results
runs-on: ubuntu-latest
needs: [summary]
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
timeout-minutes: 5
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Download all benchmark artifacts
uses: actions/download-artifact@v4
with:
pattern: bench-*
path: benchmark-results
merge-multiple: true
- name: Generate docs data
run: |
mkdir -p docs-data
node .github/scripts/generate-docs-data.js \
--type benchmarks \
--results-dir benchmark-results \
--output docs-data/benchmark-results.json \
--commit "${{ github.sha }}" \
--branch "${{ github.ref_name }}"
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs-data
destination_dir: ci
keep_files: true