[CI] Add cross-job fast-fail health check (Layer 3) (#21341)

This commit is contained in:
Liangsheng Yin
2026-03-24 16:58:56 -07:00
committed by GitHub
parent 1046dbe038
commit 3937a07b17
5 changed files with 105 additions and 0 deletions
@@ -0,0 +1,42 @@
name: Check Stage Health
description: Fail fast if any job in the current workflow run has already failed. Auto-skips for scheduled runs.
inputs:
github-token:
description: 'GitHub token for API calls'
required: false
default: ${{ github.token }}
runs:
using: composite
steps:
- name: Check stage health
uses: actions/github-script@v7
with:
github-token: ${{ inputs.github-token }}
script: |
// Skip for scheduled runs — they should collect all failures, not fast-fail
if (context.eventName === 'schedule') {
core.info('Skipping health check for scheduled run');
return;
}
const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
per_page: 100,
});
// Find jobs that failed from a real error, not from fast-fail cascade
const rootCauseFailures = jobs.filter(j => {
if (j.status !== 'completed' || j.conclusion !== 'failure') return false;
// If the failing step is the health check, it's a cascade — skip it
const failedStep = (j.steps || []).find(s => s.conclusion === 'failure');
if (failedStep && (failedStep.name.includes('check-stage-health') || failedStep.name.includes('Check stage health'))) {
return false;
}
return true;
});
if (rootCauseFailures.length > 0) {
core.setFailed(`Fast-fail: skipping — root cause job(s): ${rootCauseFailures.map(j => j.name).join(', ')}`);
}