Skip to content

Commit

Permalink
fix: query all repo runs to not rely on run id being provided
Browse files Browse the repository at this point in the history
We can only get a workflow run when a run id was provided. As this is not
always the case get all workflow runs of the repo and set the workflow later
on in case it wasn't set.
  • Loading branch information
romangg committed Feb 14, 2024
1 parent 7ca6a11 commit 55c01b1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ async function main() {
core.info(`==> Artifact name: ${name}`)
core.info(`==> Local path: ${path}`)

if (!workflow) {
if (!workflow && runID) {
const run = await client.rest.actions.getWorkflowRun({
owner: owner,
repo: repo,
run_id: runID || github.context.runId,
run_id: runID,
})
workflow = run.data.workflow_id
}
Expand Down Expand Up @@ -107,16 +107,20 @@ 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, {
for await (const runs of client.paginate.iterator(client.rest.actions.listWorkflowRunsForRepo, {
owner: owner,
repo: repo,
workflow_id: workflow,
...(branch ? { branch } : {}),
...(event ? { event } : {}),
...(commit ? { head_sha: commit } : {}),
}
)) {
for (const run of runs.data) {
if (workflow && run.workflow_id != workflow) {
continue
}
if (commit && run.head_sha != commit) {
continue
}
if (runNumber && run.run_number != runNumber) {
continue
}
Expand Down Expand Up @@ -151,6 +155,15 @@ async function main() {
runID = run.id
core.info(`==> (found) Run ID: ${runID}`)
core.info(`==> (found) Run date: ${run.created_at}`)
if (!workflow) {
const run = await client.rest.actions.getWorkflowRun({
owner: owner,
repo: repo,
run_id: runID,
})
workflow = run.data.workflow_id
core.info(`==> Workflow name: ${workflow}`)
}
break
}
if (runID) {
Expand Down

0 comments on commit 55c01b1

Please sign in to comment.