Skip to content

Commit 09385b7

Browse files
martcusmarcolovazzanodawidd6
authored
Search capability (dawidd6#122)
Co-authored-by: martcus <marco.lovazzano@accenture.com> Co-authored-by: Dawid Dziurla <dawidd0811@gmail.com>
1 parent af92a84 commit 09385b7

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
5151
# then will get the last available artifact from previous workflow
5252
# default false, just try to download from the last one
5353
check_artifacts: false
54+
# Optional, search for the last workflow run whose stored an artifact named as in `name` input
55+
# default false
56+
search_artifacts: false
5457
```

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ inputs:
5151
check_artifacts:
5252
description: Check workflow run whether it has an artifact
5353
required: false
54+
search_artifacts:
55+
description: Search workflow runs for artifact with specified name
56+
required: false
5457
runs:
5558
using: node12
5659
main: main.js

main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ async function main() {
2020
let runID = core.getInput("run_id")
2121
let runNumber = core.getInput("run_number")
2222
let checkArtifacts = core.getInput("check_artifacts")
23+
let searchArtifacts = core.getInput("search_artifacts")
2324

2425
const client = github.getOctokit(token)
2526

@@ -76,7 +77,7 @@ async function main() {
7677
if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) {
7778
continue
7879
}
79-
if (checkArtifacts) {
80+
if (checkArtifacts || searchArtifacts) {
8081
let artifacts = await client.actions.listWorkflowRunArtifacts({
8182
owner: owner,
8283
repo: repo,
@@ -85,6 +86,14 @@ async function main() {
8586
if (artifacts.data.artifacts.length == 0) {
8687
continue
8788
}
89+
if (searchArtifacts) {
90+
const artifact = artifacts.data.artifacts.find((artifact) => {
91+
return artifact.name == name
92+
})
93+
if (!artifact) {
94+
continue
95+
}
96+
}
8897
}
8998
runID = run.id
9099
break
@@ -152,3 +161,4 @@ async function main() {
152161
}
153162

154163
main()
164+

0 commit comments

Comments
 (0)