diff --git a/README.md b/README.md index cc37bbf2..29605035 100644 --- a/README.md +++ b/README.md @@ -46,4 +46,8 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar path: extract_here # Optional, defaults to current repo repo: ${{github.repository}} + # Optional, check the workflow run whether it has an artifact + # then will get the last available artifact from previous workflow + # default false, just try to download from the last one + check_artifacts: false ``` diff --git a/action.yml b/action.yml index ac2a779b..7d8ef100 100644 --- a/action.yml +++ b/action.yml @@ -48,6 +48,9 @@ inputs: description: Where to unpack the artifact required: false default: "./" + check_artifacts: + description: Check workflow run whether it has an artifact + required: false runs: using: node12 main: main.js diff --git a/main.js b/main.js index 738ea408..d72c8c7f 100644 --- a/main.js +++ b/main.js @@ -19,6 +19,7 @@ async function main() { let event = core.getInput("event") let runID = core.getInput("run_id") let runNumber = core.getInput("run_number") + let checkArtifacts = core.getInput("check_artifacts") const client = github.getOctokit(token) @@ -75,6 +76,16 @@ async function main() { if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) { continue } + if (checkArtifacts) { + let artifacts = await client.actions.listWorkflowRunArtifacts({ + owner: owner, + repo: repo, + run_id: run.id, + }) + if (artifacts.data.artifacts.length == 0) { + continue + } + } runID = run.id break }