From 2eb4abcd5ee84431339bf659b39e81274b7ccf54 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Tue, 27 Apr 2021 10:26:41 +0200 Subject: [PATCH] Try to reduce API calls in check_artifact_exists --- .github/actions/check_artifact_exists/main.js | 39 +++++-------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/.github/actions/check_artifact_exists/main.js b/.github/actions/check_artifact_exists/main.js index e7608aa19c..b86b5e3ea4 100644 --- a/.github/actions/check_artifact_exists/main.js +++ b/.github/actions/check_artifact_exists/main.js @@ -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() {