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

Attempt to ensure that we download the latest artifact #241

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion action.yml
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
23 changes: 17 additions & 6 deletions main.js
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,8 +104,9 @@ async function main() {
}

if (!runID) {
// Note that the runs are returned in most recent first order.
for await (const runs of client.paginate.iterator(client.rest.actions.listWorkflowRuns, {
// 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,
workflow_id: workflow,
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