-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
70 deletions.
There are no files selected for viewing
This file contains 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 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 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,69 @@ | ||
name: Wait for Tests | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
test-job-name: | ||
required: true | ||
type: string | ||
description: "Name of the test job to wait for" | ||
|
||
jobs: | ||
wait-for-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Wait for tests to complete | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const { owner, repo } = context.repo; | ||
const ref = context.sha; | ||
let attempts = 0; | ||
const maxAttempts = 30; // 5 minutes max wait time | ||
const testJobName = '${{ inputs.test-job-name }}'; | ||
while (attempts < maxAttempts) { | ||
attempts++; | ||
console.log(`Attempt ${attempts}: Checking test status...`); | ||
try { | ||
const { data: allChecks } = await github.rest.checks.listForRef({ | ||
owner, | ||
repo, | ||
ref | ||
}); | ||
console.log(`Found ${allChecks.check_runs.length} total check runs.`); | ||
console.log(`Check run names: ${allChecks.check_runs.map(run => run.name).join(', ')}`); | ||
const testRun = allChecks.check_runs.find(run => run.name === testJobName); | ||
if (testRun) { | ||
console.log(`Found '${testJobName}' check. Status: ${testRun.status}, conclusion: ${testRun.conclusion}`); | ||
if (testRun.status === 'completed') { | ||
if (testRun.conclusion === 'success') { | ||
console.log('Tests passed!'); | ||
process.exit(0); | ||
} else { | ||
throw new Error(`Tests failed with conclusion: ${testRun.conclusion}`); | ||
} | ||
} else { | ||
console.log(`Test run is still in progress. Status: ${testRun.status}`); | ||
} | ||
} else { | ||
console.log(`'${testJobName}' check not found yet. Waiting...`); | ||
} | ||
} catch (error) { | ||
console.error(`Error occurred: ${error.message}`); | ||
if (attempts >= maxAttempts) { | ||
throw error; | ||
} | ||
} | ||
console.log('Waiting 10 seconds before next attempt...'); | ||
await new Promise(r => setTimeout(r, 10000)); | ||
} | ||
throw new Error('Timeout: Max attempts reached without finding completed tests.'); |