Repository navigation
improvement(ci): start http e2e jobs beside the e2e build #10244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env bash | ||
| # Blocks until this run's `build (e2e)` job finishes, so an e2e job can check out, install and | ||
| # migrate while the build runs instead of after it. Exits 0 only when that job succeeded; a failed, | ||
| # cancelled or skipped build, a missing or duplicated build job, or a failed API call exits non-zero. | ||
| # The job's own timeout bounds the wait. | ||
| # | ||
| # Usage: wait-for-e2e-build.sh (reads GITHUB_REPOSITORY and GITHUB_RUN_ID; needs `actions: read`) | ||
| set -euo pipefail | ||
|
|
||
| : "${GITHUB_REPOSITORY:?}" | ||
| : "${GITHUB_RUN_ID:?}" | ||
|
|
||
| poll_seconds=${E2E_BUILD_POLL_SECONDS:-10} | ||
| started=$SECONDS | ||
|
|
||
| while :; do | ||
| # `filter=latest` lists each job's latest attempt, so re-running only a failed e2e job still sees | ||
| # the build an earlier attempt finished. Called from ci.yml the name carries a `checks / ` prefix. | ||
| state=$(gh api --paginate "repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/jobs?filter=latest&per_page=100" \ | ||
| --jq '.jobs[] | select(.name == "build (e2e)" or (.name | endswith(" / build (e2e)"))) | ||
| | "\(.status) \(.conclusion // "")"') | ||
| matches=$(printf '%s' "$state" | grep -c . || true) | ||
| if [ "$matches" -ne 1 ]; then | ||
| echo "::error::Expected one build (e2e) job in this run, found $matches." | ||
| exit 1 | ||
| fi | ||
| read -r status conclusion <<< "$state" | ||
| if [ "$status" = completed ]; then | ||
| if [ "$conclusion" = success ]; then | ||
| echo "build (e2e) finished; waited $((SECONDS - started))s" | ||
| exit 0 | ||
| fi | ||
| echo "::error::build (e2e) finished with '$conclusion'; there is no build to test." | ||
| exit 1 | ||
| fi | ||
| sleep "$poll_seconds" | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { spawnSync } from 'node:child_process' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| const script = fileURLToPath(new URL('../.github/scripts/wait-for-e2e-build.sh', import.meta.url)) | ||
|
|
||
| interface Job { | ||
| name: string | ||
| status: string | ||
| conclusion: string | null | ||
| } | ||
|
|
||
| const job = (status: string, conclusion: string | null = null, name = 'checks / build (e2e)') => ({ | ||
| name, | ||
| status, | ||
| conclusion, | ||
| }) | ||
|
|
||
| /** | ||
| * Runs the real script against a `gh` stub whose jq filter is the script's own: each poll answers | ||
| * with the next listing (the last one repeats), and `sleep` only counts polls. | ||
| */ | ||
| function runWait(listings: Job[][], apiStatus = 0) { | ||
| return spawnSync( | ||
| 'bash', | ||
| [ | ||
| '-c', | ||
| `set -euo pipefail | ||
| poll=0 | ||
| gh() { | ||
| [ "$1" = api ] && [ "$2" = --paginate ] || return 97 | ||
| case "$3" in | ||
| 'repos/example/project/actions/runs/7/jobs?filter=latest&per_page=100') ;; | ||
| *) return 98 ;; | ||
| esac | ||
| if [ "$API_STATUS" -ne 0 ]; then return "$API_STATUS"; fi | ||
| local listings count | ||
| listings=$(jq -c '.' <<< "$LISTINGS") | ||
| count=$(jq 'length' <<< "$listings") | ||
| local index=$(( poll < count ? poll : count - 1 )) | ||
| jq -r "{jobs: .[$index]} | $5" <<< "$listings" | ||
| } | ||
| sleep() { poll=$((poll + 1)); } | ||
| source "$1"`, | ||
| 'wait-for-e2e-build-fixture', | ||
| script, | ||
| ], | ||
| { | ||
| timeout: 5_000, | ||
| encoding: 'utf8', | ||
| env: { | ||
| PATH: process.env.PATH, | ||
| GITHUB_REPOSITORY: 'example/project', | ||
| GITHUB_RUN_ID: '7', | ||
| LISTINGS: JSON.stringify(listings), | ||
| API_STATUS: String(apiStatus), | ||
| }, | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| describe('wait-for-e2e-build.sh', () => { | ||
| it('returns once an in-progress build succeeds', () => { | ||
| const result = runWait([ | ||
| [job('queued'), job('in_progress', null, 'checks / lint')], | ||
| [job('in_progress')], | ||
| [job('completed', 'success')], | ||
| ]) | ||
| expect(result.status).toBe(0) | ||
| expect(result.stdout).toContain('build (e2e) finished') | ||
| }) | ||
|
|
||
| it('accepts the unprefixed job name of a directly dispatched checks run', () => { | ||
| expect(runWait([[job('completed', 'success', 'build (e2e)')]]).status).toBe(0) | ||
| }) | ||
|
|
||
| it.each(['failure', 'cancelled', 'skipped', 'timed_out'])( | ||
| 'fails when the build ends %s', | ||
| (end) => { | ||
| const result = runWait([[job('in_progress')], [job('completed', end)]]) | ||
| expect(result.status).toBe(1) | ||
| expect(result.stdout).toContain(`finished with '${end}'`) | ||
| } | ||
| ) | ||
|
|
||
| it('fails when the run has no build job instead of waiting forever', () => { | ||
| const result = runWait([[job('completed', 'success', 'checks / build')]]) | ||
| expect(result.status).toBe(1) | ||
| expect(result.stdout).toContain('found 0') | ||
| }) | ||
|
|
||
| it('fails when two jobs claim the build name', () => { | ||
| const result = runWait([ | ||
| [job('completed', 'success'), job('completed', 'success', 'build (e2e)')], | ||
| ]) | ||
| expect(result.status).toBe(1) | ||
| expect(result.stdout).toContain('found 2') | ||
| }) | ||
|
|
||
| it('fails on an API error rather than treating it as still building', () => { | ||
| const result = runWait([[job('in_progress')]], 1) | ||
| expect(result.status).not.toBe(0) | ||
| expect(result.stdout).not.toContain('build (e2e) finished') | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.