Browse Source

Fix download old-ish artifacts (#67)

* Add per_page arg

* Add multiple pages

* Fix

* Fix
pull/69/head
Michał Chęciński 3 years ago committed by GitHub
parent
commit
850faad0cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 81
      download-artifacts/main.js

81
download-artifacts/main.js

@ -56,46 +56,59 @@ async function main() { @@ -56,46 +56,59 @@ async function main() {
}
if (!runID) {
let runs = await client.actions.listWorkflowRuns({
owner: owner,
repo: repo,
workflow_id: workflow
}).then(workflowRunsResponse => {
return workflowRunsResponse.data.workflow_runs
.sort((a, b) => {
a_date = new Date(a.created_at)
b_date = new Date(b.created_at)
// descending order
return b_date - a_date
})
})
if (branch) {
runs = runs.filter(run => run.head_branch == branch)
}
for (let pageNumber = 1; pageNumber < 5 && !runID; pageNumber++) {
let runs = await client.actions.listWorkflowRuns({
owner: owner,
repo: repo,
workflow_id: workflow,
per_page: 100,
page: pageNumber
}).then(workflowRunsResponse => {
return workflowRunsResponse.data.workflow_runs
.sort((a, b) => {
a_date = new Date(a.created_at)
b_date = new Date(b.created_at)
// descending order
return b_date - a_date
})
})
for (const run of runs) {
if (commit && run.head_sha != commit) {
continue
}
if (runNumber && run.run_number != runNumber) {
continue
if (branch) {
runs = runs.filter(run => run.head_branch == branch)
}
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) {
for (const run of runs) {
if (commit && run.head_sha != commit) {
continue
}
if (runNumber && run.run_number != runNumber) {
continue
}
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
}
if (runID) {
break
}
runID = run.id
break
}
if (!runID) {
throw new Error("no matching workflow run found in last 500 runs")
}
}

Loading…
Cancel
Save