Skip to content

Commit 800c47f

Browse files
committed
Improve docs-only guard input handling
1 parent 6ed3527 commit 800c47f

File tree

1 file changed

+34
-14
lines changed
  • .github/actions/ensure-master-docs-safety

1 file changed

+34
-14
lines changed

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

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@ runs:
1313
- name: Check previous master commit status
1414
if: ${{ inputs.docs-only == 'true' && inputs.previous-sha != '' && inputs.previous-sha != '0000000000000000000000000000000000000000' }}
1515
uses: actions/github-script@v7
16+
env:
17+
PREVIOUS_SHA: ${{ inputs.previous-sha }}
1618
with:
1719
script: |
18-
const previousSha = core.getInput('previous-sha');
19-
const workflowRuns = await github.paginate(
20-
github.rest.actions.listWorkflowRunsForRepo,
21-
{
22-
owner: context.repo.owner,
23-
repo: context.repo.repo,
24-
branch: 'master',
25-
per_page: 100
26-
}
27-
);
20+
const previousSha = process.env.PREVIOUS_SHA;
21+
if (!previousSha) {
22+
core.info('No previous SHA found, skipping safety check.');
23+
return;
24+
}
25+
26+
const createdAfter = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7).toISOString();
27+
const workflowRuns = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, {
28+
owner: context.repo.owner,
29+
repo: context.repo.repo,
30+
branch: 'master',
31+
event: 'push',
32+
per_page: 50,
33+
created: `>${createdAfter}`
34+
});
2835
2936
const relevantRuns = workflowRuns.filter((run) => run.head_sha === previousSha);
3037
@@ -41,11 +48,24 @@ runs:
4148
}
4249
}
4350
51+
const incompleteRuns = Array.from(latestByWorkflow.values()).filter(
52+
(run) => run.status !== 'completed'
53+
);
54+
55+
if (incompleteRuns.length > 0) {
56+
const details = incompleteRuns
57+
.map((run) => `- ${run.name} (run #${run.run_number}) is still ${run.status}`)
58+
.join('\n');
59+
core.setFailed(
60+
[
61+
`Cannot skip CI for docs-only commit because previous master commit ${previousSha} still has running workflows:`,
62+
details
63+
].join('\n')
64+
);
65+
return;
66+
}
67+
4468
const failingRuns = Array.from(latestByWorkflow.values()).filter((run) => {
45-
if (run.status !== 'completed') {
46-
core.info(`Workflow ${run.name} (#${run.id}) is still ${run.status}; ignoring for enforcement.`);
47-
return false;
48-
}
4969
return ['failure', 'timed_out', 'cancelled', 'action_required'].includes(run.conclusion);
5070
});
5171

0 commit comments

Comments
 (0)