Try to reduce API calls in check_artifact_exists

This commit is contained in:
Reuben Morais 2021-04-27 10:26:41 +02:00
parent 93128cae5f
commit 5ddd7e0fa2
3 changed files with 15 additions and 32 deletions

View File

@ -8,51 +8,30 @@ 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 [];
}
async function main() {
const token = core.getInput("github_token", { required: true });
const [owner, repo] = core.getInput("repo", { required: true }).split("/");

View File

@ -79,7 +79,8 @@
"@octokit/openapi-types": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-6.0.0.tgz",
"integrity": "sha512-CnDdK7ivHkBtJYzWzZm7gEkanA7gKH6a09Eguz7flHw//GacPJLmkHA3f3N++MJmlxD1Fl+mB7B32EEpSCwztQ=="
"integrity": "sha512-CnDdK7ivHkBtJYzWzZm7gEkanA7gKH6a09Eguz7flHw//GacPJLmkHA3f3N++MJmlxD1Fl+mB7B32EEpSCwztQ==",
"dev": true
},
"@octokit/plugin-paginate-rest": {
"version": "2.13.3",
@ -104,6 +105,7 @@
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-3.4.1.tgz",
"integrity": "sha512-qCQ+Z4AnL9OrXvV59EH3GzPxsB+WyqufoCjiCJXJxTbnt3W+leXbXw5vHrMp4NG9ltw00McFWIxIxNQAzLNoTA==",
"dev": true,
"requires": {
"@octokit/types": "^6.0.1",
"bottleneck": "^2.15.3"
@ -138,6 +140,7 @@
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.13.0.tgz",
"integrity": "sha512-W2J9qlVIU11jMwKHUp5/rbVUeErqelCsO5vW5PKNb7wAXQVUz87Rc+imjlEvpvbH8yUb+KHmv8NEjVZdsdpyxA==",
"dev": true,
"requires": {
"@octokit/openapi-types": "^6.0.0"
}
@ -163,7 +166,8 @@
"bottleneck": {
"version": "2.19.5",
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==",
"dev": true
},
"deprecation": {
"version": "2.3.1",