Skip to content

Commit

Permalink
Try to reduce API calls in check_artifact_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
reuben committed Apr 27, 2021
1 parent 4a73246 commit d183c26
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 62 deletions.
39 changes: 9 additions & 30 deletions .github/actions/check_artifact_exists/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,28 @@ const { throttling } = __nccwpck_require__(9968);
const { GitHub } = __nccwpck_require__(3030);

async function getGoodArtifacts(client, owner, repo, name) {
const goodWorkflowArtifacts = await client.paginate(
"GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts",
{
owner: owner,
repo: repo,
run_id: github.context.runId,
},
(workflowArtifacts) => {
// console.log(" ==> workflowArtifacts", workflowArtifacts);
return workflowArtifacts.data.filter((a) => {
// console.log("==> Artifact check", a);
return a.name == name
})
}
);

console.log("==> maybe goodWorkflowArtifacts:", goodWorkflowArtifacts);
if (goodWorkflowArtifacts.length > 0) {
return goodWorkflowArtifacts;
}

const goodRepoArtifacts = await client.paginate(
"GET /repos/{owner}/{repo}/actions/artifacts",
{
owner: owner,
repo: repo,
per_page: 100,
},
(repoArtifacts) => {
(repoArtifacts, done) => {
// console.log(" ==> repoArtifacts", repoArtifacts);
return repoArtifacts.data.filter((a) => {
const goodArtifacts = repoArtifacts.data.filter((a) => {
// console.log("==> Artifact check", a);
return a.name == name
})
});
if (goodArtifacts.length > 0) {
done();
}
return goodArtifacts;
}
);

console.log("==> maybe goodRepoArtifacts:", goodRepoArtifacts);
if (goodRepoArtifacts.length > 0) {
return goodRepoArtifacts;
}

// We have not been able to find a repo artifact, it's really no good news
return [];
return goodRepoArtifacts;
}

async function main() {
Expand Down
39 changes: 9 additions & 30 deletions .github/actions/check_artifact_exists/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,28 @@ const { throttling } = require('@octokit/plugin-throttling');
const { GitHub } = require('@actions/github/lib/utils');

async function getGoodArtifacts(client, owner, repo, name) {
const goodWorkflowArtifacts = await client.paginate(
"GET /repos/{owner}/{repo}/actions/runs/{run_id}/artifacts",
{
owner: owner,
repo: repo,
run_id: github.context.runId,
},
(workflowArtifacts) => {
// console.log(" ==> workflowArtifacts", workflowArtifacts);
return workflowArtifacts.data.filter((a) => {
// console.log("==> Artifact check", a);
return a.name == name
})
}
);

console.log("==> maybe goodWorkflowArtifacts:", goodWorkflowArtifacts);
if (goodWorkflowArtifacts.length > 0) {
return goodWorkflowArtifacts;
}

const goodRepoArtifacts = await client.paginate(
"GET /repos/{owner}/{repo}/actions/artifacts",
{
owner: owner,
repo: repo,
per_page: 100,
},
(repoArtifacts) => {
(repoArtifacts, done) => {
// console.log(" ==> repoArtifacts", repoArtifacts);
return repoArtifacts.data.filter((a) => {
const goodArtifacts = repoArtifacts.data.filter((a) => {
// console.log("==> Artifact check", a);
return a.name == name
})
});
if (goodArtifacts.length > 0) {
done();
}
return goodArtifacts;
}
);

console.log("==> maybe goodRepoArtifacts:", goodRepoArtifacts);
if (goodRepoArtifacts.length > 0) {
return goodRepoArtifacts;
}

// We have not been able to find a repo artifact, it's really no good news
return [];
return goodRepoArtifacts;
}

async function main() {
Expand Down
8 changes: 6 additions & 2 deletions .github/actions/check_artifact_exists/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d183c26

Please sign in to comment.