From 750b71af351aba467757d7be6924199bb08db4ed Mon Sep 17 00:00:00 2001 From: HyukjinKwon Date: Thu, 13 Aug 2020 17:51:55 +0900 Subject: [PATCH] Add the support to omit artifact name --- action.yml | 2 +- main.js | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/action.yml b/action.yml index abbe03ae..478d4ff6 100644 --- a/action.yml +++ b/action.yml @@ -27,7 +27,7 @@ inputs: required: false name: description: Artifact name - required: true + required: false path: description: Where to unpack the artifact required: false diff --git a/main.js b/main.js index 78b6cc7a..e0e0a756 100644 --- a/main.js +++ b/main.js @@ -8,9 +8,9 @@ async function main() { try { const token = core.getInput("github_token", { required: true }) const workflow = core.getInput("workflow", { required: true }) - const name = core.getInput("name", { required: true }) const [owner, repo] = core.getInput("repo", { required: true }).split("/") const path = core.getInput("path", { required: true }) + const name = core.getInput("name") let branch = core.getInput("branch") let pr = core.getInput("pr") let commit = core.getInput("commit") @@ -82,30 +82,38 @@ async function main() { run_id: run.id, }) - const artifact = artifacts.data.artifacts.find((artifact) => { - return artifact.name == name - }) + let atfs; + if (name) { + atfs = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == name + }) + } + else { + artfs = artifacts.data.artifacts + } - console.log("==> Artifact:", artifact.id) + for (const artifact of artfs) { + console.log("==> Artifact:", artifact.id) - const size = filesize(artifact.size_in_bytes, { base: 10 }) + const size = filesize(artifact.size_in_bytes, { base: 10 }) - console.log("==> Downloading:", name + ".zip", `(${size})`) + console.log("==> Downloading:", name + ".zip", `(${size})`) - const zip = await client.actions.downloadArtifact({ - owner: owner, - repo: repo, - artifact_id: artifact.id, - archive_format: "zip", - }) + const zip = await client.actions.downloadArtifact({ + owner: owner, + repo: repo, + artifact_id: artifact.id, + archive_format: "zip", + }) - const adm = new AdmZip(Buffer.from(zip.data)) - adm.getEntries().forEach((entry) => { - const action = entry.isDirectory ? "creating" : "inflating" - const filepath = pathname.join(path, entry.entryName) - console.log(` ${action}: ${filepath}`) - }) - adm.extractAllTo(path, true) + const adm = new AdmZip(Buffer.from(zip.data)) + adm.getEntries().forEach((entry) => { + const action = entry.isDirectory ? "creating" : "inflating" + const filepath = pathname.join(path, entry.entryName) + console.log(` ${action}: ${filepath}`) + }) + adm.extractAllTo(path, true) + } } catch (error) { core.setFailed(error.message) }