-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from pedrox-hs/workflows/alls-green
Create alls-green.yml
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Alls green | ||
|
||
on: | ||
push: | ||
pull_request: | ||
types: [ labeled, ready_for_review ] | ||
pull_request_review: | ||
types: [ dismissed ] | ||
|
||
concurrency: | ||
group: alls-green-${{ github.sha }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
alls-green-check: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Wait on checks | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const checkInterval = 30000; // 30 seconds | ||
const jobName = context.job; | ||
let hasPendingChecks = true; | ||
while (hasPendingChecks) { | ||
let { data: { check_runs: checkRuns } } = await github.rest.checks.listForRef({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
ref: context.sha, | ||
per_page: 100, | ||
}); | ||
checkRuns = checkRuns.filter(checkRun => checkRun.name !== jobName).map(checkRun => { | ||
return { | ||
name: checkRun.name, | ||
status: checkRun.status, | ||
conclusion: checkRun.conclusion, | ||
}; | ||
}); | ||
// check if all is completed | ||
const pendingChecks = checkRuns.filter(checkRun => checkRun.status !== 'completed'); | ||
hasPendingChecks = pendingChecks.length > 0; | ||
if (!hasPendingChecks || checkRuns.length === 0) { | ||
// check if all check runs completions is success or neutral | ||
const allSuccess = checkRuns.every(checkRun => checkRun.conclusion === 'success' || checkRun.conclusion === 'neutral'); | ||
// if not success workfow is failed | ||
if (!allSuccess) { | ||
core.setFailed('Not all checks are successful'); | ||
return; | ||
} | ||
} | ||
github.log.warn(`Waiting for checks to complete.`); | ||
github.log.warn(JSON.stringify(checkRuns, null, 2)); | ||
await new Promise(resolve => setTimeout(resolve, checkInterval)); | ||
} |