Skip to content

Commit dc9ff1a

Browse files
committed
Guard master docs-only pushes and ensure full CI runs
1 parent 3d35c3a commit dc9ff1a

File tree

1 file changed

+17
-3
lines changed
  • .github/actions/ensure-master-docs-safety

1 file changed

+17
-3
lines changed

.github/actions/ensure-master-docs-safety/action.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ runs:
2323
return;
2424
}
2525
26+
// Query workflow runs from the last 7 days to avoid excessive API calls
27+
// For very old commits, we'll skip the check rather than scan the entire history
2628
const createdAfter = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7).toISOString();
2729
const workflowRuns = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, {
2830
owner: context.repo.owner,
2931
repo: context.repo.repo,
3032
branch: 'master',
3133
event: 'push',
32-
per_page: 50,
34+
per_page: 100,
3335
created: `>${createdAfter}`
3436
});
3537
@@ -40,6 +42,8 @@ runs:
4042
return;
4143
}
4244
45+
// Deduplicate workflow runs by keeping only the latest run for each workflow_id
46+
// This handles cases where workflows are re-run manually
4347
const latestByWorkflow = new Map();
4448
for (const run of relevantRuns) {
4549
const existing = latestByWorkflow.get(run.workflow_id);
@@ -48,6 +52,9 @@ runs:
4852
}
4953
}
5054
55+
// Check for workflows that are still running
56+
// We require all workflows to complete before allowing docs-only skip
57+
// This prevents skipping CI when the previous commit hasn't been fully validated
5158
const incompleteRuns = Array.from(latestByWorkflow.values()).filter(
5259
(run) => run.status !== 'completed'
5360
);
@@ -59,12 +66,17 @@ runs:
5966
core.setFailed(
6067
[
6168
`Cannot skip CI for docs-only commit because previous master commit ${previousSha} still has running workflows:`,
62-
details
69+
details,
70+
'',
71+
'Wait for these workflows to complete before pushing docs-only changes.'
6372
].join('\n')
6473
);
6574
return;
6675
}
6776
77+
// Check for workflows that failed on the previous commit
78+
// We treat cancelled runs as failures to be conservative, since they might indicate
79+
// timeouts or other infrastructure issues that should be resolved before skipping CI
6880
const failingRuns = Array.from(latestByWorkflow.values()).filter((run) => {
6981
return ['failure', 'timed_out', 'cancelled', 'action_required'].includes(run.conclusion);
7082
});
@@ -81,6 +93,8 @@ runs:
8193
core.setFailed(
8294
[
8395
`Cannot skip CI for docs-only commit because previous master commit ${previousSha} still has failing workflows:`,
84-
details
96+
details,
97+
'',
98+
'Fix these failures before pushing docs-only changes, or push non-docs changes to trigger full CI.'
8599
].join('\n')
86100
);

0 commit comments

Comments
 (0)