Skip to content

Commit d183c26

Browse files
committed
Try to reduce API calls in check_artifact_exists
1 parent 4a73246 commit d183c26

File tree

3 files changed

+24
-62
lines changed

3 files changed

+24
-62
lines changed

.github/actions/check_artifact_exists/dist/index.js

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,28 @@ const { throttling } = __nccwpck_require__(9968);
1515
const { GitHub } = __nccwpck_require__(3030);
1616

1717
async function getGoodArtifacts(client, owner, repo, name) {
18-
const goodWorkflowArtifacts = await client.paginate(
19-
"GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts",
20-
{
21-
owner: owner,
22-
repo: repo,
23-
run_id: github.context.runId,
24-
},
25-
(workflowArtifacts) => {
26-
// console.log(" ==> workflowArtifacts", workflowArtifacts);
27-
return workflowArtifacts.data.filter((a) => {
28-
// console.log("==> Artifact check", a);
29-
return a.name == name
30-
})
31-
}
32-
);
33-
34-
console.log("==> maybe goodWorkflowArtifacts:", goodWorkflowArtifacts);
35-
if (goodWorkflowArtifacts.length > 0) {
36-
return goodWorkflowArtifacts;
37-
}
38-
3918
const goodRepoArtifacts = await client.paginate(
4019
"GET /repos/{owner}/{repo}/actions/artifacts",
4120
{
4221
owner: owner,
4322
repo: repo,
23+
per_page: 100,
4424
},
45-
(repoArtifacts) => {
25+
(repoArtifacts, done) => {
4626
// console.log(" ==> repoArtifacts", repoArtifacts);
47-
return repoArtifacts.data.filter((a) => {
27+
const goodArtifacts = repoArtifacts.data.filter((a) => {
4828
// console.log("==> Artifact check", a);
4929
return a.name == name
50-
})
30+
});
31+
if (goodArtifacts.length > 0) {
32+
done();
33+
}
34+
return goodArtifacts;
5135
}
5236
);
5337

5438
console.log("==> maybe goodRepoArtifacts:", goodRepoArtifacts);
55-
if (goodRepoArtifacts.length > 0) {
56-
return goodRepoArtifacts;
57-
}
58-
59-
// We have not been able to find a repo artifact, it's really no good news
60-
return [];
39+
return goodRepoArtifacts;
6140
}
6241

6342
async function main() {

.github/actions/check_artifact_exists/main.js

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,28 @@ const { throttling } = require('@octokit/plugin-throttling');
88
const { GitHub } = require('@actions/github/lib/utils');
99

1010
async function getGoodArtifacts(client, owner, repo, name) {
11-
const goodWorkflowArtifacts = await client.paginate(
12-
"GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts",
13-
{
14-
owner: owner,
15-
repo: repo,
16-
run_id: github.context.runId,
17-
},
18-
(workflowArtifacts) => {
19-
// console.log(" ==> workflowArtifacts", workflowArtifacts);
20-
return workflowArtifacts.data.filter((a) => {
21-
// console.log("==> Artifact check", a);
22-
return a.name == name
23-
})
24-
}
25-
);
26-
27-
console.log("==> maybe goodWorkflowArtifacts:", goodWorkflowArtifacts);
28-
if (goodWorkflowArtifacts.length > 0) {
29-
return goodWorkflowArtifacts;
30-
}
31-
3211
const goodRepoArtifacts = await client.paginate(
3312
"GET /repos/{owner}/{repo}/actions/artifacts",
3413
{
3514
owner: owner,
3615
repo: repo,
16+
per_page: 100,
3717
},
38-
(repoArtifacts) => {
18+
(repoArtifacts, done) => {
3919
// console.log(" ==> repoArtifacts", repoArtifacts);
40-
return repoArtifacts.data.filter((a) => {
20+
const goodArtifacts = repoArtifacts.data.filter((a) => {
4121
// console.log("==> Artifact check", a);
4222
return a.name == name
43-
})
23+
});
24+
if (goodArtifacts.length > 0) {
25+
done();
26+
}
27+
return goodArtifacts;
4428
}
4529
);
4630

4731
console.log("==> maybe goodRepoArtifacts:", goodRepoArtifacts);
48-
if (goodRepoArtifacts.length > 0) {
49-
return goodRepoArtifacts;
50-
}
51-
52-
// We have not been able to find a repo artifact, it's really no good news
53-
return [];
32+
return goodRepoArtifacts;
5433
}
5534

5635
async function main() {

.github/actions/check_artifact_exists/package-lock.json

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)