forked from vercel/vercel
-
Notifications
You must be signed in to change notification settings - Fork 0
633 lines (570 loc) · 26.8 KB
/
Copy pathtest.yml
File metadata and controls
633 lines (570 loc) · 26.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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
name: Tests
on:
pull_request:
branches:
- main
permissions:
contents: read
checks: read
deployments: read
issues: write
pull-requests: write
statuses: write
env:
VERCEL_TELEMETRY_DISABLED: '1'
TURBO_REMOTE_ONLY: 'true'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
setup:
name: Find Changes
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
statuses: write
outputs:
unitTests: ${{ steps['set-tests'].outputs['unitTests'] }}
e2eTests: ${{ steps['set-tests'].outputs['e2eTests'] }}
baseSha: ${{ steps.pr-context.outputs.baseSha }}
headSha: ${{ steps.pr-context.outputs.headSha }}
prNumber: ${{ steps.pr-context.outputs.prNumber }}
affectedPackages: ${{ steps['affected-packages'].outputs['packages'] }}
testStrategy: ${{ steps['affected-packages'].outputs['strategy'] }}
affectedCount: ${{ steps['affected-packages'].outputs['count'] }}
totalCount: ${{ steps['affected-packages'].outputs['total'] }}
allPackages: ${{ steps['affected-packages'].outputs['allPackages'] }}
steps:
- name: Resolve PR context
id: pr-context
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
echo "prNumber=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "baseSha=$BASE_SHA" >> $GITHUB_OUTPUT
echo "headSha=$HEAD_SHA" >> $GITHUB_OUTPUT
# The `context` here MUST exactly match the one written by the
# `Report status to PR commit` step in the `summary` job below.
# GitHub commit statuses are upserted by `(sha, context)`, so a
# mismatch would create a second row instead of overwriting this
# pending one with the final result.
- name: Post pending Summary status to PR commit
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ steps.pr-context.outputs.headSha }}',
state: 'pending',
context: 'Summary',
target_url: `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`,
description: 'Tests in progress',
});
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ steps.pr-context.outputs.headSha }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Turborepo Remote Cache
uses: vercel/setup-turborepo-remote-cache-action@3df3d75a5268bbe2a4ee66048f56f3a86d6e21b7
with:
team: ${{ vars.TURBO_TEAM }}
- uses: actions/setup-node@v4
with:
node-version: 22
- name: install turbo@2.10.8
run: npm i -g turbo@2.10.8
- id: affected-packages
run: |
# Set base SHA for affected package detection
export TURBO_BASE_SHA="${{ steps.pr-context.outputs.baseSha }}"
# Get affected packages info for PR comment
AFFECTED_OUTPUT=$(node utils/test-affected.js "${{ steps.pr-context.outputs.baseSha }}" 2>&1)
# Extract affected packages count and total packages count
PACKAGE_COUNT=$(echo "$AFFECTED_OUTPUT" | grep -o "Found [0-9]* affected packages" | grep -o "[0-9]*" | head -1 || echo "0")
TOTAL_COUNT=$(echo "$AFFECTED_OUTPUT" | grep -o "Total packages with tests: [0-9]*" | grep -o "[0-9]*" | head -1 || echo "0")
if echo "$AFFECTED_OUTPUT" | grep -q "config or workflow changes detected"; then
STRATEGY="all-e2e"
elif echo "$AFFECTED_OUTPUT" | grep -q "test-all result detected"; then
STRATEGY="test-all"
elif [ "$PACKAGE_COUNT" -gt "0" ]; then
STRATEGY="affected-only"
else
STRATEGY="no-tests"
fi
# Get the list of affected packages
PACKAGES=$(echo "$AFFECTED_OUTPUT" | sed -n '/Affected packages that would be tested:/,/This would result in the following turbo filters:/p' | grep " - " | sed 's/ - //' | tr '\n' ',' | sed 's/,$//')
# Get all packages (trim whitespace and newlines)
ALL_PACKAGES=$(echo "$AFFECTED_OUTPUT" | grep "All packages with tests:" | sed 's/All packages with tests: //' | head -1 | xargs)
# Debug output
echo "PACKAGE_COUNT=$PACKAGE_COUNT"
echo "TOTAL_COUNT=$TOTAL_COUNT"
echo "STRATEGY=$STRATEGY"
echo "strategy=$STRATEGY" >> $GITHUB_OUTPUT
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
echo "count=$PACKAGE_COUNT" >> $GITHUB_OUTPUT
echo "total=$TOTAL_COUNT" >> $GITHUB_OUTPUT
echo "allPackages=$ALL_PACKAGES" >> $GITHUB_OUTPUT
- id: set-tests
run: |
UNIT_TESTS_ARRAY=$(TEST_TYPE=unit node utils/chunk-tests.js)
E2E_TESTS_ARRAY=$(TEST_TYPE=e2e node utils/chunk-tests.js)
echo "Unit tests to run:"
echo "$UNIT_TESTS_ARRAY"
echo "E2E tests to run:"
echo "$E2E_TESTS_ARRAY"
echo "unitTests=$UNIT_TESTS_ARRAY" >> $GITHUB_OUTPUT
echo "e2eTests=$E2E_TESTS_ARRAY" >> $GITHUB_OUTPUT
env:
TURBO_BASE_SHA: ${{ steps.pr-context.outputs.baseSha }}
comment-test-strategy:
name: Comment Test Strategy
runs-on: ubuntu-latest
continue-on-error: true
needs:
- setup
steps:
- name: Comment PR with test strategy
uses: actions/github-script@v7
with:
script: |
const strategy = '${{ needs.setup.outputs.testStrategy }}';
const packages = '${{ needs.setup.outputs.affectedPackages }}';
const allPackages = '${{ needs.setup.outputs.allPackages }}';
const affectedCount = parseInt('${{ needs.setup.outputs.affectedCount }}') || 0;
const totalCount = parseInt('${{ needs.setup.outputs.totalCount }}') || 0;
const baseSha = '${{ needs.setup.outputs.baseSha }}';
const headSha = '${{ needs.setup.outputs.headSha }}';
const prNumber = ${{ needs.setup.outputs.prNumber }};
const percentage = totalCount > 0 ? Math.round((affectedCount / totalCount) * 100) : 0;
const unaffectedCount = totalCount - affectedCount;
const unaffectedPercentage = totalCount > 0 ? Math.round((unaffectedCount / totalCount) * 100) : 0;
const affectedSet = packages ? new Set(packages.split(',').map(p => p.trim())) : new Set();
const allPackagesList = allPackages ? allPackages.split(',').map(p => p.trim()) : [];
const unaffectedPackages = allPackagesList.filter(pkg => !affectedSet.has(pkg));
const unaffectedList = unaffectedPackages.map(p => `1. \`${p}\``).join('\n');
let message = '## 🧪 Unit Test Strategy\n\n';
message += `**Comparing**: [\`${baseSha.substring(0, 7)}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${baseSha}) → [\`${headSha.substring(0, 7)}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${headSha}) ([view diff](https://github.com/${context.repo.owner}/${context.repo.repo}/compare/${baseSha}...${headSha}))\n\n`;
if (strategy === 'all-e2e') {
message += '**Strategy**: Code changed outside of a package - running all unit tests\n\n';
message += '⚠️ All unit tests will run because global code changes could impact all packages.\n\n';
if (packages) {
const packageList = packages.split(',').map(p => `1. \`${p.trim()}\``).join('\n');
message += `<details>\n<summary>Affected packages - ${affectedCount} (${percentage}%)</summary>\n\n${packageList}\n\n</details>\n\n`;
}
if (unaffectedCount > 0) {
message += `<details>\n<summary>Unaffected packages - ${unaffectedCount} (${unaffectedPercentage}%)</summary>\n\n${unaffectedList || '_No unaffected packages_'}\n\n</details>\n\n`;
}
message += '### Results\n\n';
message += '- **Unit tests**: All affected packages will run unit tests\n';
message += '- **E2E tests**: Running in parallel in this workflow\n';
message += '- **Type checks**: All affected packages will run type checks';
} else if (strategy === 'affected-only') {
message += '**Strategy**: Affected packages only\n\n';
message += '✅ Only testing packages that have been modified or depend on modified packages.\n\n';
if (packages) {
const packageList = packages.split(',').map(p => `1. \`${p.trim()}\``).join('\n');
message += `<details>\n<summary>Affected packages - ${affectedCount} (${percentage}%)</summary>\n\n${packageList}\n\n</details>\n\n`;
}
if (unaffectedCount > 0) {
message += `<details>\n<summary>Unaffected packages - ${unaffectedCount} (${unaffectedPercentage}%)</summary>\n\n${unaffectedList || '_No unaffected packages_'}\n\n</details>\n\n`;
}
message += '### Results\n\n';
message += '- **Unit tests**: Only affected packages will run unit tests\n';
message += '- **E2E tests**: Running in parallel in this workflow\n';
message += '- **Type checks**: Only affected packages will run type checks';
} else if (strategy === 'no-tests') {
message += '**Strategy**: No tests needed\n\n';
message += '✨ No packages affected - skipping tests\n\n';
message += '### Results\n\n';
message += '- **Unit tests**: None\n';
message += '- **E2E tests**: Running in parallel in this workflow\n';
message += '- **Type checks**: None';
} else if (strategy === 'test-all') {
message += '**Strategy**: Full unit test suite\n\n';
message += '🔄 Running all unit tests (unable to determine affected packages)\n\n';
if (packages) {
const packageList = packages.split(',').map(p => `1. \`${p.trim()}\``).join('\n');
message += `<details>\n<summary>Affected packages - ${affectedCount} (${percentage}%)</summary>\n\n${packageList}\n\n</details>\n\n`;
}
if (unaffectedCount > 0) {
message += `<details>\n<summary>Unaffected packages - ${unaffectedCount} (${unaffectedPercentage}%)</summary>\n\n${unaffectedList || '_No unaffected packages_'}\n\n</details>\n\n`;
}
message += '### Results\n\n';
message += '- **Unit tests**: All packages will run unit tests\n';
message += '- **E2E tests**: Running in parallel in this workflow\n';
message += '- **Type checks**: All packages will run type checks';
} else {
message += '**Strategy**: Unknown\n\n';
message += `⚠️ Unknown strategy: ${strategy}\n\n`;
message += '### Results\n\n';
message += '- **Unit tests**: Unknown\n';
message += '- **E2E tests**: Running in parallel in this workflow\n';
message += '- **Type checks**: Unknown';
}
message += '\n\n---\n*This comment is automatically generated based on the [affected testing strategy](.github/AFFECTED_TESTING.md)*';
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existingComment = comments.find(comment =>
comment.user.login === 'github-actions[bot]' &&
(comment.body.includes('## 🧪 Unit Test Strategy') || comment.body.includes('## 🧪 Test Strategy'))
);
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: message
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: message
});
}
unit-test:
timeout-minutes: 120
runs-on: ${{ matrix.runner }}
name: Unit / ${{ matrix.label }}
permissions:
contents: read
id-token: write
if: ${{ needs.setup.outputs['unitTests'] != '[]' }}
needs:
- setup
strategy:
fail-fast: false
max-parallel: 75
matrix:
include: ${{ fromJson(needs.setup.outputs['unitTests']) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.setup.outputs.headSha }}
- name: Setup Turborepo Remote Cache
uses: vercel/setup-turborepo-remote-cache-action@3df3d75a5268bbe2a4ee66048f56f3a86d6e21b7
with:
team: ${{ vars.TURBO_TEAM }}
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.nodeVersion }}
- name: Setup Go toolchain
if: ${{ matrix.needsGo == true }}
uses: actions/setup-go@v6
with:
go-version: '1.23.12'
cache: false
- name: Setup Rust toolchain
if: ${{ matrix.needsRust == true }}
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
with:
toolchain: '1.96.1'
targets: wasm32-wasip2
# yarn 1.22.21 introduced a Corepack bug when running tests.
# this can be removed once https://github.com/yarnpkg/yarn/issues/9015 is resolved
- name: install yarn@1.22.19
run: npm i -g yarn@1.22.19
- name: install pnpm@10.29.3
run: npm i -g pnpm@10.29.3
- name: install uv@0.10.11
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
with:
version: '0.10.11'
- run: pnpm install
- name: "Print test manifest (chunk ${{matrix.chunkNumber}}/${{matrix.allChunksLength}})"
shell: bash
env:
VITEST_TEST_FILES: ${{ matrix.useEnvPaths == true && join(matrix.testPaths, ' ') || '' }}
run: |
# Resolve the file list the same way the test step does
if [ -n "$VITEST_TEST_FILES" ]; then
files="$VITEST_TEST_FILES"
source="VITEST_TEST_FILES env var"
else
files="${{ join(matrix.testPaths, ' ') }}"
source="CLI args"
fi
count=$(echo "$files" | tr ' ' '\n' | grep -c .)
echo "Chunk ${{matrix.chunkNumber}} of ${{matrix.allChunksLength}} — $count files via $source"
echo "$files" | tr ' ' '\n' | grep . | sort | sed 's/^/ /'
{
echo "## Chunk ${{matrix.chunkNumber}}/${{matrix.allChunksLength}} — \`${{matrix.packageName}}\`"
echo "| | |"
echo "|---|---|"
echo "| Runner | \`${{matrix.runner}}\` / Node v\`${{matrix.nodeVersion}}\` |"
echo "| Files | $count (via $source) |"
echo ""
echo "<details><summary>File list</summary>"
echo ""
echo '```'
echo "$files" | tr ' ' '\n' | grep . | sort
echo '```'
echo "</details>"
} >> "$GITHUB_STEP_SUMMARY"
- name: Test ${{matrix.packageName}}
timeout-minutes: 25
run: |
attempt=1
max_attempts=2
export NODE_OPTIONS="--require=${GITHUB_WORKSPACE}/utils/dd-trace-ci-init.js"
while [ "$attempt" -le "$max_attempts" ]; do
echo "Running tests (attempt $attempt/$max_attempts): ${{matrix.testScript}} ${{matrix.packageName}}"
# When VITEST_TEST_FILES is set, the test script reads paths from that env var
# instead of CLI args, avoiding the Windows cmd.exe ~8191 char arg limit.
if [ -n "$VITEST_TEST_FILES" ]; then
run_cmd="node utils/gen.js && node_modules/.bin/turbo run ${{matrix.testScript}} --summarize --cache-dir='.turbo' --log-order=stream --filter=${{matrix.packageName}}"
else
run_cmd="node utils/gen.js && node_modules/.bin/turbo run ${{matrix.testScript}} --summarize --cache-dir='.turbo' --log-order=stream --filter=${{matrix.packageName}} -- ${{ join(matrix.testPaths, ' ') }}"
fi
if eval "$run_cmd"; then
exit 0
fi
if [ "$attempt" -eq "$max_attempts" ]; then
echo "Tests failed after $max_attempts attempts."
exit 1
fi
echo "Tests failed; retrying once..."
attempt=$((attempt+1))
done
shell: bash
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_TEAM_ID: ${{ secrets.VERCEL_TEAM_ID }}
TURBO_BASE_SHA: ${{ needs.setup.outputs.baseSha }}
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
FORCE_COLOR: '1'
VITEST_TEST_FILES: ${{ matrix.useEnvPaths == true && join(matrix.testPaths, ' ') || '' }}
# Datadog Test Optimization: emit per-test spans correlated to the
# GitHub Actions job span, replacing the previous post-hoc JUnit
# upload. See test/lib/deployment/metrics.js for the legacy
# DATADOG_API_KEY consumer (custom transient-error metrics).
DD_CIVISIBILITY_AGENTLESS_ENABLED: 'true'
DD_API_KEY: ${{ secrets.DATADOG_API_KEY_CLI }}
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY_CLI }}
DD_ENV: ci
DD_SERVICE: vercel-cli
DD_PROFILING_ENABLED: 'false'
DD_NATIVE_METRICS: 'false'
e2e-test:
timeout-minutes: 120
runs-on: ${{ matrix.runner }}
name: E2E / ${{ matrix.label }}
permissions:
contents: read
deployments: read
id-token: write
statuses: read
if: ${{ needs.setup.outputs['e2eTests'] != '[]' }}
needs:
- setup
strategy:
fail-fast: false
max-parallel: 75
matrix:
include: ${{ fromJson(needs.setup.outputs['e2eTests']) }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.setup.outputs.headSha }}
- name: Setup Turborepo Remote Cache
uses: vercel/setup-turborepo-remote-cache-action@3df3d75a5268bbe2a4ee66048f56f3a86d6e21b7
with:
team: ${{ vars.TURBO_TEAM }}
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.nodeVersion }}
- name: Setup Go toolchain
if: ${{ matrix.needsGo == true }}
uses: actions/setup-go@v6
with:
go-version: '1.23.12'
cache: false
- name: Setup Rust toolchain
if: ${{ matrix.needsRust == true }}
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
with:
toolchain: '1.96.1'
targets: wasm32-wasip2
# yarn 1.22.21 introduced a Corepack bug when running tests.
# this can be removed once https://github.com/yarnpkg/yarn/issues/9015 is resolved
- name: install yarn@1.22.19
run: npm i -g yarn@1.22.19
- name: install pnpm@10.29.3
run: npm i -g pnpm@10.29.3
- name: Install uv
uses: astral-sh/setup-uv@eac588ad8def6316056a12d4907a9d4d84ff7a3b # v7.3.0
with:
version: '0.10.11'
- name: Install Ruby + Bundler
if: ${{ matrix.packageName == 'vercel' }}
uses: ruby/setup-ruby@9eb537ca036ebaed86729dcb9309076e4c5c3b74 # v1.314.0
with:
ruby-version: '3.3'
- run: pnpm install
- name: Wait for deployment tarballs
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_SHA: ${{ needs.setup.outputs.headSha }}
run: |
set -euo pipefail
# E2E needs the CLI and Python wheel tarballs produced by the Vercel
# preview deployment, but the workflow now starts on pull_request so
# tests can begin before the deployment-ready repository_dispatch.
# Vercel already reports successful deployments back to GitHub via
# deployment statuses and commit statuses. We poll those GitHub-owned
# records for candidate public URLs, then trust a URL only after the
# actual tarball endpoint responds. That final HTTP check is the
# readiness gate, so stale/unrelated status URLs are harmless.
validate_deployment_url() {
local url="${1%/}"
if [ -z "$url" ]; then
return 1
fi
if curl -fsI "$url/tarballs/vercel.tgz" >/dev/null; then
echo "DPL_URL=$url" >> "$GITHUB_ENV"
echo "VERCEL_CLI_VERSION=$url/tarballs/vercel.tgz" >> "$GITHUB_ENV"
echo "Deployment tarball is ready at $url/tarballs/vercel.tgz"
return 0
fi
return 1
}
get_candidate_urls() {
gh api "repos/${GITHUB_REPOSITORY}/deployments?sha=${HEAD_SHA}&per_page=20" \
--jq '.[].id' | while IFS= read -r deployment_id; do
gh api "repos/${GITHUB_REPOSITORY}/deployments/${deployment_id}/statuses" \
--jq '.[] | select(.state == "success" and .environment_url != null and .environment_url != "") | .environment_url'
done
gh api "repos/${GITHUB_REPOSITORY}/commits/${HEAD_SHA}/status" \
--jq '.statuses[] | select(.state == "success" and .target_url != null and .target_url != "") | .target_url'
}
for attempt in {1..120}; do
while IFS= read -r candidate_url; do
if validate_deployment_url "$candidate_url"; then
exit 0
fi
done < <(get_candidate_urls | sort -u)
echo "Deployment tarball is not ready yet (attempt $attempt/120)."
sleep 10
done
echo "Timed out waiting for deployment tarball."
exit 1
- name: Resolve Python wheel URLs
shell: bash
run: |
DEPLOYMENT_URL="$DPL_URL"
PACKAGES_JSON="$(node utils/get-python-packages.js)"
if [ -z "$PACKAGES_JSON" ] || [ "$PACKAGES_JSON" = "[]" ]; then
echo "No Python packages discovered; skipping wheel URL resolution."
exit 0
fi
echo "$PACKAGES_JSON" | jq -c '.[]' | while IFS= read -r package; do
package_slug="$(echo "$package" | jq -r '.packageDir')"
package_name="$(echo "$package" | jq -r '.packageName')"
wheel_name="$(curl -sf "$DEPLOYMENT_URL/tarballs/$package_slug-wheel.json" | jq -r '.filename' || echo "")"
if [ -z "$wheel_name" ]; then
continue
fi
env_var="$(printf '%s' "$package_name" | tr -c '[:alnum:]' '_' | tr '[:lower:]' '[:upper:]')_PYTHON"
echo "$env_var=$package_name @ $DEPLOYMENT_URL/tarballs/$wheel_name" >> "$GITHUB_ENV"
done
- name: Test ${{matrix.packageName}}
timeout-minutes: 35
run: |
attempt=1
max_attempts=2
export NODE_OPTIONS="--require=${GITHUB_WORKSPACE}/utils/dd-trace-ci-init.js"
while [ "$attempt" -le "$max_attempts" ]; do
echo "Running tests (attempt $attempt/$max_attempts): ${{matrix.testScript}} ${{matrix.packageName}}"
if node utils/gen.js && node_modules/.bin/turbo run ${{matrix.testScript}} --summarize --cache-dir=".turbo" --log-order=stream --filter=${{matrix.packageName}} -- ${{ join(matrix.testPaths, ' ') }}; then
exit 0
fi
if [ "$attempt" -eq "$max_attempts" ]; then
echo "Tests failed after $max_attempts attempts."
exit 1
fi
echo "Tests failed; retrying once..."
attempt=$((attempt+1))
done
shell: bash
env:
# Per-package pip install specs (e.g. VERCEL_RUNTIME_PYTHON,
# VERCEL_WORKERS_PYTHON) are also available here, injected into
# $GITHUB_ENV by the "Resolve Python wheel URLs" step above.
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_TEAM_ID: ${{ secrets.VERCEL_TEAM_ID }}
TURBO_BASE_SHA: ${{ needs.setup.outputs.baseSha }}
FORCE_COLOR: '1'
# Datadog Test Optimization: emit per-test spans correlated to the
# GitHub Actions job span, replacing the previous post-hoc JUnit
# upload. See test/lib/deployment/metrics.js for the legacy
# DATADOG_API_KEY consumer (custom transient-error metrics).
DD_CIVISIBILITY_AGENTLESS_ENABLED: 'true'
DD_API_KEY: ${{ secrets.DATADOG_API_KEY_CLI }}
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY_CLI }}
DD_ENV: ci
DD_SERVICE: vercel-cli
DD_PROFILING_ENABLED: 'false'
DD_NATIVE_METRICS: 'false'
summary:
name: Summary
runs-on: ubuntu-latest
timeout-minutes: 5
if: always()
needs:
- setup
- unit-test
- e2e-test
permissions:
statuses: write
steps:
- name: Check All
id: check-all
continue-on-error: true
run: |-
for status in ${{ join(needs.*.result, ' ') }}
do
if [ "$status" != "success" ] && [ "$status" != "skipped" ]
then
echo "Some checks failed"
echo "state=failure" >> $GITHUB_OUTPUT
exit 1
fi
done
echo "state=success" >> $GITHUB_OUTPUT
# The `context` here MUST exactly match the one written by the
# `Post pending Summary status to PR commit` step in the `setup`
# job above so this final write overwrites that pending row
# instead of creating a duplicate.
- name: Report status to PR commit
if: ${{ always() && needs.setup.outputs.headSha }}
uses: actions/github-script@v7
env:
CHECK_STATE: ${{ steps.check-all.outputs.state }}
with:
script: |
const state = process.env.CHECK_STATE === 'success' ? 'success' : 'failure';
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ needs.setup.outputs.headSha }}',
state,
context: 'Summary',
target_url: `${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`,
description: state === 'success' ? 'All checks passed' : 'Some checks failed',
});
- name: Fail the job if Check All failed
if: ${{ steps.check-all.outcome == 'failure' }}
run: exit 1