Skip to content

Commit 255bff9

Browse files
committed
fix(pr): avoid endless waiting
1 parent 8da7907 commit 255bff9

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

pr/checks-rerun/action.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,35 @@ runs:
2323
const repo = context.repo.repo;
2424
const headSha = context.payload.pull_request.head.sha;
2525
26+
// Fetch all runs for the workflow and HEAD SHA (no status filter)
2627
const runs = await github.rest.actions.listWorkflowRunsForRepo({
2728
owner,
2829
repo,
2930
workflow_id: '${{ inputs.workflow-id }}',
3031
event: 'pull_request',
3132
head_sha: headSha,
32-
status: 'completed',
3333
});
3434
35-
const run = runs.data.workflow_runs[0];
36-
if (run) {
35+
// If there's an in-progress, queued, or waiting run, skip rerun to avoid
36+
// concurrency deadlock ("waiting for PR to complete before running")
37+
const activeRun = runs.data.workflow_runs.find(r =>
38+
['in_progress', 'queued', 'waiting', 'pending', 'requested'].includes(r.status)
39+
);
40+
if (activeRun) {
41+
core.info(`Workflow run ${activeRun.id} is already ${activeRun.status}, skipping rerun.`);
42+
return;
43+
}
44+
45+
// Find the latest completed run and rerun its failed jobs
46+
const completedRun = runs.data.workflow_runs.find(r => r.status === 'completed');
47+
if (completedRun) {
48+
core.info(`Rerunning failed jobs for run ${completedRun.id} (conclusion: ${completedRun.conclusion})`);
3749
await github.rest.actions.reRunWorkflowFailedJobs({
3850
owner,
3951
repo,
40-
run_id: run.id,
52+
run_id: completedRun.id,
4153
});
54+
return;
4255
}
56+
57+
core.warning('No workflow runs found for the current HEAD SHA.');

0 commit comments

Comments
 (0)