diff --git a/README.md b/README.md index 9d996d47..0a0a191a 100644 --- a/README.md +++ b/README.md @@ -51,4 +51,7 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar # then will get the last available artifact from previous workflow # default false, just try to download from the last one check_artifacts: false + # Optional, search for the last workflow run whose stored an artifact named as in `name` input + # default false + search_artifacts: false ``` diff --git a/action.yml b/action.yml index 7d8ef100..e3011ad9 100644 --- a/action.yml +++ b/action.yml @@ -51,6 +51,9 @@ inputs: check_artifacts: description: Check workflow run whether it has an artifact required: false + search_artifacts: + description: Search workflow runs for artifact with specified name + required: false runs: using: node12 main: main.js diff --git a/main.js b/main.js index d72c8c7f..82f14c1e 100644 --- a/main.js +++ b/main.js @@ -20,6 +20,7 @@ async function main() { let runID = core.getInput("run_id") let runNumber = core.getInput("run_number") let checkArtifacts = core.getInput("check_artifacts") + let searchArtifacts = core.getInput("search_artifacts") const client = github.getOctokit(token) @@ -76,7 +77,7 @@ async function main() { if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) { continue } - if (checkArtifacts) { + if (checkArtifacts || searchArtifacts) { let artifacts = await client.actions.listWorkflowRunArtifacts({ owner: owner, repo: repo, @@ -85,6 +86,14 @@ async function main() { if (artifacts.data.artifacts.length == 0) { continue } + if (searchArtifacts) { + const artifact = artifacts.data.artifacts.find((artifact) => { + return artifact.name == name + }) + if (!artifact) { + continue + } + } } runID = run.id break @@ -152,3 +161,4 @@ async function main() { } main() +