Repository navigation
ci: gate merge on CI completion and enable core package Node unit tests #9719
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
Open
shivanee-p
wants to merge
4
commits into
main
Choose a base branch
from
shivaneep-ci-upgrade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e4974a3
ci: gate merge on CI completion and enable core package Node unit tests
shivanee-p cbb42fa
ci: wrap wait-for-ci polling loop in try-catch for transient API errors
shivanee-p 75a2288
ci: fall back to context.sha when pull_request payload is absent
shivanee-p 853142b
ci: avoid subshell parentheses in run_conditional_tests.sh conditionals
shivanee-p 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,132 @@ | ||
| name: "Wait for CI" | ||
| description: "Waits for all PR CI workflow runs to finish and verifies generator-tests succeeded when applicable" | ||
| inputs: | ||
| generator-changed: | ||
| required: false | ||
| default: "false" | ||
| description: "Whether generator files were modified in the PR" | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Wait for all CI workflows to finish | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 | ||
| env: | ||
| GENERATOR_CHANGED: ${{ inputs.generator-changed }} | ||
| with: | ||
| script: | | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const headSha = context.payload.pull_request?.head?.sha || context.sha; | ||
| const generatorChanged = process.env.GENERATOR_CHANGED === 'true'; | ||
| const pollIntervalMs = 30000; | ||
| const maxWaitMs = 46 * 60 * 1000; | ||
| const startTime = Date.now(); | ||
| const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | ||
|
|
||
| const isPresubmitUnitWorkflow = run => | ||
| run.path === '.github/workflows/presubmit.yaml' || | ||
| run.path === '.github/workflows/windows-presubmit.yaml' || | ||
| run.name === 'presubmit' || | ||
| run.name === 'presubmit-windows'; | ||
|
|
||
| const isGateJob = jobName => | ||
| jobName === 'Wait for CI' || /^units \(\d+\)$/.test(jobName); | ||
|
|
||
| const isGeneratorWorkflow = run => | ||
| run.path === '.github/workflows/generator-tests.yaml' || | ||
| run.name === 'generator-tests'; | ||
|
|
||
| while (Date.now() - startTime < maxWaitMs) { | ||
| try { | ||
| const { data: { workflow_runs: runs } } = await github.rest.actions.listWorkflowRunsForRepo({ | ||
| owner, | ||
| repo, | ||
| head_sha: headSha, | ||
| event: 'pull_request', | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| // Keep only the most recent workflow run per workflow_id | ||
| const latestByWorkflow = new Map(); | ||
| for (const run of runs) { | ||
| const existing = latestByWorkflow.get(run.workflow_id); | ||
| if (!existing || new Date(run.created_at) > new Date(existing.created_at)) { | ||
| latestByWorkflow.set(run.workflow_id, run); | ||
| } | ||
| } | ||
|
|
||
| const pendingItems = []; | ||
| let generatorRun = null; | ||
|
|
||
| for (const run of latestByWorkflow.values()) { | ||
| if (isGeneratorWorkflow(run)) { | ||
| generatorRun = run; | ||
| } | ||
|
|
||
| if (isPresubmitUnitWorkflow(run)) { | ||
| if (run.status === 'completed') { | ||
| continue; | ||
| } | ||
| const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({ | ||
| owner, | ||
| repo, | ||
| run_id: run.id, | ||
| per_page: 100, | ||
| }); | ||
| const workJobs = jobs.filter(j => !isGateJob(j.name)); | ||
| if (workJobs.length === 0) { | ||
| pendingItems.push(`${run.name} (initializing jobs)`); | ||
| } else { | ||
| const runningJobs = workJobs.filter(j => j.status !== 'completed'); | ||
| for (const j of runningJobs) { | ||
| pendingItems.push(`${run.name} / ${j.name} (${j.status})`); | ||
| } | ||
| } | ||
| } else if (run.status !== 'completed') { | ||
| pendingItems.push(`${run.name} (${run.status})`); | ||
| } | ||
| } | ||
|
|
||
| if (generatorChanged && !generatorRun) { | ||
| pendingItems.push('generator-tests (waiting for workflow run to register)'); | ||
| } | ||
|
|
||
| if (pendingItems.length === 0) { | ||
| core.info(`All CI workflows for SHA ${headSha} have finished.`); | ||
| for (const run of latestByWorkflow.values()) { | ||
| if (isPresubmitUnitWorkflow(run)) { | ||
| continue; | ||
| } | ||
| core.info(`- ${run.name}: conclusion=${run.conclusion} (${run.html_url})`); | ||
| if ( | ||
| !isGeneratorWorkflow(run) && | ||
| run.conclusion !== 'success' && | ||
| run.conclusion !== 'skipped' && | ||
| run.conclusion !== 'neutral' | ||
| ) { | ||
| core.warning(`Non-required workflow '${run.name}' finished with conclusion '${run.conclusion}': ${run.html_url}`); | ||
| } | ||
| } | ||
|
|
||
| if (generatorRun && generatorRun.conclusion !== 'success' && generatorRun.conclusion !== 'skipped') { | ||
| core.setFailed(`generator-tests finished with conclusion '${generatorRun.conclusion}': ${generatorRun.html_url}`); | ||
| return; | ||
| } | ||
| if (generatorChanged && (!generatorRun || generatorRun.conclusion !== 'success')) { | ||
| core.setFailed( | ||
| `generator-tests did not succeed (conclusion: ${generatorRun ? generatorRun.conclusion : 'missing'})`, | ||
| ); | ||
| return; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| core.info(`Waiting for ${pendingItems.length} CI step(s) to finish:\n- ${pendingItems.join('\n- ')}`); | ||
| } catch (err) { | ||
| core.warning(`Error polling CI workflow status (will retry in ${pollIntervalMs / 1000}s): ${err instanceof Error ? err.message : String(err)}`); | ||
| } | ||
|
|
||
| await sleep(pollIntervalMs); | ||
| } | ||
|
|
||
| core.setFailed(`Timed out waiting for CI workflows to finish on SHA ${headSha}`); | ||
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
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.