|
| 1 | +name: CI Status |
| 2 | + |
| 3 | +run-name: Aggregate CI check status |
| 4 | + |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + - 'release-[0-9]+.[0-9]+.x' |
| 10 | + merge_group: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + - 'release-[0-9]+.[0-9]+.x' |
| 14 | + |
| 15 | +concurrency: |
| 16 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 17 | + cancel-in-progress: true |
| 18 | + |
| 19 | +jobs: |
| 20 | + ci-status: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 60 |
| 23 | + permissions: |
| 24 | + checks: read |
| 25 | + steps: |
| 26 | + - name: Wait for CI checks to complete |
| 27 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 |
| 28 | + with: |
| 29 | + script: | |
| 30 | + const sha = context.payload.pull_request?.head.sha ?? context.sha; |
| 31 | + const owner = context.repo.owner; |
| 32 | + const repo = context.repo.repo; |
| 33 | +
|
| 34 | + // Wait for other workflows to get queued |
| 35 | + core.info('Waiting 60s for CI workflows to get queued...'); |
| 36 | + await new Promise(r => setTimeout(r, 60000)); |
| 37 | +
|
| 38 | + const excludedChecks = new Set(['ci-status']); |
| 39 | + const excludedApps = new Set(['mergify']); |
| 40 | +
|
| 41 | + const terminalStatuses = new Set(['completed']); |
| 42 | + const successConclusions = new Set(['success', 'skipped', 'neutral']); |
| 43 | + const failureConclusions = new Set(['failure', 'cancelled', 'timed_out']); |
| 44 | +
|
| 45 | + while (true) { |
| 46 | + const { data: checkRuns } = await github.rest.checks.listForRef({ |
| 47 | + owner, |
| 48 | + repo, |
| 49 | + ref: sha, |
| 50 | + per_page: 100, |
| 51 | + }); |
| 52 | +
|
| 53 | + // Filter to only GitHub Actions checks, excluding ourselves and bots |
| 54 | + const relevant = checkRuns.check_runs.filter(cr => { |
| 55 | + if (excludedChecks.has(cr.name)) return false; |
| 56 | + if (cr.app && excludedApps.has(cr.app.slug)) return false; |
| 57 | + // Only include GitHub Actions checks |
| 58 | + if (!cr.app || cr.app.slug !== 'github-actions') return false; |
| 59 | + return true; |
| 60 | + }); |
| 61 | +
|
| 62 | + if (relevant.length === 0) { |
| 63 | + core.info('No other CI checks found yet, waiting...'); |
| 64 | + await new Promise(r => setTimeout(r, 30000)); |
| 65 | + continue; |
| 66 | + } |
| 67 | +
|
| 68 | + const pending = relevant.filter(cr => !terminalStatuses.has(cr.status)); |
| 69 | + const completed = relevant.filter(cr => terminalStatuses.has(cr.status)); |
| 70 | +
|
| 71 | + core.info(`Checks: ${completed.length} completed, ${pending.length} pending out of ${relevant.length} total`); |
| 72 | +
|
| 73 | + for (const cr of completed) { |
| 74 | + core.info(` ✓ ${cr.name}: ${cr.conclusion}`); |
| 75 | + } |
| 76 | + for (const cr of pending) { |
| 77 | + core.info(` ⏳ ${cr.name}: ${cr.status}`); |
| 78 | + } |
| 79 | +
|
| 80 | + if (pending.length > 0) { |
| 81 | + core.info('Waiting 30s for pending checks...'); |
| 82 | + await new Promise(r => setTimeout(r, 30000)); |
| 83 | + continue; |
| 84 | + } |
| 85 | +
|
| 86 | + // All checks completed — evaluate conclusions |
| 87 | + const failed = completed.filter(cr => failureConclusions.has(cr.conclusion)); |
| 88 | +
|
| 89 | + if (failed.length > 0) { |
| 90 | + for (const cr of failed) { |
| 91 | + core.error(`${cr.name} concluded with: ${cr.conclusion}`); |
| 92 | + } |
| 93 | + core.setFailed(`${failed.length} CI check(s) failed.`); |
| 94 | + return; |
| 95 | + } |
| 96 | +
|
| 97 | + const succeeded = completed.filter(cr => successConclusions.has(cr.conclusion)); |
| 98 | + core.info(`All ${succeeded.length} CI checks passed.`); |
| 99 | + return; |
| 100 | + } |
0 commit comments