Skip to content

Commit a31fb18

Browse files
authored
Merge pull request #22 from modestustr/development
ci(publish): reduce duplicate publish runs
2 parents f7c56cb + 7c15693 commit a31fb18

1 file changed

Lines changed: 36 additions & 13 deletions

File tree

.github/workflows/publish.yml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Publish NuGet Package
22

33
on:
44
workflow_run:
5-
workflows: ['Security Pentest Suite', 'Build & Test Suite']
5+
workflows: ['Build & Test Suite']
66
branches: [ master ]
77
types: [ completed ]
88
workflow_dispatch:
@@ -40,18 +40,41 @@ jobs:
4040
const branch = context.payload.workflow_run?.head_branch || 'master';
4141
const required = ['Security Pentest Suite', 'Build & Test Suite'];
4242
43-
const { data } = await github.rest.actions.listWorkflowRunsForRepo({
44-
owner: context.repo.owner,
45-
repo: context.repo.repo,
46-
head_sha: sha,
47-
branch,
48-
per_page: 100
49-
});
50-
51-
const runs = data.workflow_runs || [];
52-
const allPassed = required.every(name =>
53-
runs.some(r => r.name === name && r.conclusion === 'success')
54-
);
43+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
44+
const maxAttempts = 30;
45+
const waitMs = 10000;
46+
47+
let runs = [];
48+
let allPassed = false;
49+
50+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
51+
const { data } = await github.rest.actions.listWorkflowRunsForRepo({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
head_sha: sha,
55+
branch,
56+
per_page: 100
57+
});
58+
59+
runs = data.workflow_runs || [];
60+
allPassed = required.every(name =>
61+
runs.some(r => r.name === name && r.conclusion === 'success')
62+
);
63+
64+
if (allPassed) {
65+
break;
66+
}
67+
68+
const allCompleted = required.every(name =>
69+
runs.some(r => r.name === name && r.status === 'completed')
70+
);
71+
72+
if (allCompleted) {
73+
break;
74+
}
75+
76+
await sleep(waitMs);
77+
}
5578
5679
if (!allPassed) {
5780
const snapshot = required

0 commit comments

Comments
 (0)