Skip to content

Commit

Permalink
Add 'ensure_latest' because we're still sometimes getting artifacts t…
Browse files Browse the repository at this point in the history
…hat are a couple days old
  • Loading branch information
dsnopek committed May 17, 2023
1 parent 91dda23 commit 1322f74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ inputs:
description: Search workflow runs for artifact with specified name
required: false
default: false
ensure_latest:
description: Ensures that we are using the latest available artifact
required: false
default: false
skip_unpack:
description: Choose to skip unpacking the downloaded artifact(s)
required: false
Expand All @@ -74,7 +78,7 @@ inputs:
required: false
description: |
Choose how to exit the action if no artifact is found
fail, warn or ignore
default: fail
outputs:
Expand Down
21 changes: 16 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async function main() {
let runNumber = core.getInput("run_number")
let checkArtifacts = core.getBooleanInput("check_artifacts")
let searchArtifacts = core.getBooleanInput("search_artifacts")
let ensureLatest = core.getBooleanInput("ensure_latest")
let dryRun = core.getInput("dry_run")

const client = github.getOctokit(token)
Expand Down Expand Up @@ -103,7 +104,8 @@ async function main() {
}

if (!runID) {
// Note that the runs are returned in most recent first order.
// Note that the runs are returned (roughly) in most recent first order. However, for repos
// with lots and lots of runs, this may not always be the case (hence why we need ensureLatest).
for await (const runs of client.paginate.iterator(client.rest.actions.listWorkflowRunsForRepo, {
owner: owner,
repo: repo,
Expand All @@ -113,6 +115,7 @@ async function main() {
...(commit ? { head_sha: commit } : {}),
}
)) {
let runCreatedAt = null;
for (const run of runs.data) {
if (runNumber && run.run_number != runNumber) {
continue
Expand Down Expand Up @@ -141,12 +144,20 @@ async function main() {
}
}
}
if (ensureLatest) {
if (runCreatedAt === null || ((new Date(run.created_at)) > (new Date(runCreatedAt)))) {
runID = run.id;
runCreatedAt = run.created_at;
}
continue;
}
runID = run.id
core.info(`==> (found) Run ID: ${runID}`)
core.info(`==> (found) Run date: ${run.created_at}`)
runCreatedAt = run.created_at;
break
}
if (runID) {
core.info(`==> (found) Run ID: ${runID}`)
core.info(`==> (found) Run date: ${runCreatedAt}`)
break
}
}
Expand Down Expand Up @@ -215,7 +226,7 @@ async function main() {
}

core.setOutput("found_artifact", true)

for (const artifact of artifacts) {
core.info(`==> Artifact: ${artifact.id}`)

Expand Down Expand Up @@ -270,7 +281,7 @@ async function main() {

function setExitMessage(ifNoArtifactFound, message) {
core.setOutput("found_artifact", false)

switch (ifNoArtifactFound) {
case "fail":
core.setFailed(message)
Expand Down

0 comments on commit 1322f74

Please sign in to comment.