diff --git a/README.md b/README.md index cd61f84c..f9ce2e27 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar ## Usage -> If `commit` or `pr` or `branch` or `run_id` or `workflow_conclusion` is not specified then the artifact from the most recent completed workflow run will be downloaded. +> If `commit` or `pr` or `branch` or `run_id` or `workflow_conclusion` is not specified then the artifact from the most recent successfully completed workflow run will be downloaded. -**Do not specify `pr`, `commit`, `branch`, `run_id`, `run_number` together or `workflow_conclusion` and `run_id` together. Pick just one of each or none.** +**Do not specify `pr`, `commit`, `branch`, `run_id` together or `workflow_conclusion` and `run_id` together. Pick just one of each or none.** ```yaml - name: Download artifact @@ -23,7 +23,7 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar # "failure", "success", "neutral", "cancelled", "skipped", "timed_out", "action_required" # Or a workflow status: # "completed", "in_progress", "queued" - # Default: "completed" + # Default: "completed,success" workflow_conclusion: success # Optional, will get head commit SHA pr: ${{github.event.pull_request.number}} diff --git a/action.yml b/action.yml index 0a662b9f..0984e134 100644 --- a/action.yml +++ b/action.yml @@ -13,8 +13,12 @@ inputs: description: Workflow name required: true workflow_conclusion: - description: Wanted conclusion to search for in recent runs + description: | + Wanted status or conclusion or both to search for in recent runs + + https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs required: false + default: completed,success repo: description: Repository name with owner (like actions/checkout) required: false diff --git a/main.js b/main.js index ae51952a..888b9bf8 100644 --- a/main.js +++ b/main.js @@ -5,10 +5,6 @@ const filesize = require('filesize') const pathname = require('path') const fs = require('fs') -// https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs -// allows for both status or conclusion to be used as status filter -const allowed_workflow_conclusions = ["failure", "success", "neutral", "cancelled", "skipped", "timed_out", "action_required", "queued", "in_progress", "completed"] - async function main() { try { const token = core.getInput("github_token", { required: true }) @@ -16,7 +12,7 @@ async function main() { const [owner, repo] = core.getInput("repo", { required: true }).split("/") const path = core.getInput("path", { required: true }) const name = core.getInput("name") - let workflow_conclusion = core.getInput("workflow_conclusion") + let workflowConclusion = core.getInput("workflow_conclusion") let pr = core.getInput("pr") let commit = core.getInput("commit") let branch = core.getInput("branch") @@ -25,24 +21,16 @@ async function main() { const client = github.getOctokit(token) - if ([runID, branch, pr, commit, runNumber].filter(elem => elem).length > 1) { + if ([runID, branch, pr, commit].filter(elem => elem).length > 1) { throw new Error("don't specify `run_id`, `branch`, `pr`, `commit` together") } - if ([runID, workflow_conclusion].filter((elem) => elem).length > 1) { - throw new Error("don't specify `run_id`, `workflow_conclusion` together") - } - - if (!workflow_conclusion) { - workflow_conclusion = "completed" - } - - if(!allowed_workflow_conclusions.includes(workflow_conclusion)) { - throw new Error(`Unknown workflow conclusion '${workflow_conclusion}'`) - } + console.log("==> Workflow:", workflow) console.log("==> Repo:", owner + "/" + repo) + console.log("==> Conclusion:", workflowConclusion) + if (pr) { console.log("==> PR:", pr) @@ -58,15 +46,15 @@ async function main() { console.log("==> Commit:", commit) } - if (runNumber) { - console.log("==> RunNumber:", runNumber) - } - if (branch) { branch = branch.replace(/^refs\/heads\//, "") console.log("==> Branch:", branch) } + if (runNumber) { + console.log("==> RunNumber:", runNumber) + } + if (!runID) { const endpoint = "GET /repos/:owner/:repo/actions/workflows/:id/runs?status=:status&branch=:branch" const params = { @@ -74,7 +62,7 @@ async function main() { repo: repo, id: workflow, branch: branch, - status: workflow_conclusion, + status: workflowConclusion, } for await (const runs of client.paginate.iterator(endpoint,params)) { const run = runs.data.find(r => { @@ -111,8 +99,8 @@ async function main() { artifacts = artifacts.data.artifacts } - if (artifacts.length == 0) - throw new Error("no artifacts found") + if (artifacts.length == 0) + throw new Error("no artifacts found") for (const artifact of artifacts) { console.log("==> Artifact:", artifact.id)