Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download aritfact from latest run which upload an artifact #88

Merged
merged 9 commits into from Aug 11, 2021
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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
```
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -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
11 changes: 11 additions & 0 deletions main.js
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down