Skip to content

Commit

Permalink
Merge pull request #12 from pedrox-hs/workflows/alls-green
Browse files Browse the repository at this point in the history
Create alls-green.yml
  • Loading branch information
kodiakhq[bot] authored Nov 3, 2023
2 parents 526cfb6 + b5b014c commit 1d506b4
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/alls-green.yml
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));
}

0 comments on commit 1d506b4

Please sign in to comment.