From 5ddd7e0fa262ae5024b806d9cbff2cfa94ebeada 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 --- .../check_artifact_exists/dist/index.js | Bin 361789 -> 361113 bytes .github/actions/check_artifact_exists/main.js | 39 ++++-------------- .../check_artifact_exists/package-lock.json | 8 +++- 3 files changed, 15 insertions(+), 32 deletions(-) diff --git a/.github/actions/check_artifact_exists/dist/index.js b/.github/actions/check_artifact_exists/dist/index.js index c33d562fe459c532ec0ac18660c06018b7ccca32..b20ce52b9be748e5acbe0df50946a64fc9240305 100644 GIT binary patch delta 167 zcmdnnB{s8FY(qNJWO>#_f(k%TkXjU9keHrorC?}aFnK$xGMkPJrXQVa4YpJncuT)T;DaxAaxPx# delta 458 zcmbQ)Dz>*vY(qK|M|gfwc3Mt;`Q&USzv*(OjFOX&FnKx`mFC4~rdTPYXO?7?Cg~;T z=ar;Zl;{D4JyUeJ6ri9M!PF>+n&Vhhl9`s6Tv9yQnOQ>yLsUse0VX!No>^jY+yQnD zxWGo{p6T6>m^ml!X3_KrM>o(4s5d=7KLtZV(;Doe%rpfJEb@~XcSx!frIwTy>HiLBcT8gHj9fp?(CJJeikODj5_UwOn9F=<6$l zrz&J5mZd7><(DWVrKaX7BqrsgDwO0aq-Ex%C?qNr0ZmXyga(t2LS~72F;FZqC#Mpq n1?)tHywvhyuyIg#N5?j+vbL+TG6FFZ5HkZY%XU>(){ { - // 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() { diff --git a/.github/actions/check_artifact_exists/package-lock.json b/.github/actions/check_artifact_exists/package-lock.json index 3a70ac66..fd188e3c 100644 --- a/.github/actions/check_artifact_exists/package-lock.json +++ b/.github/actions/check_artifact_exists/package-lock.json @@ -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",