Skip to content

Commit

Permalink
Merge pull request #63 from dawidd6/changes
Browse files Browse the repository at this point in the history
Specify default workflow conclusion and allow run_id together with run_number
  • Loading branch information
dawidd6 authored Mar 15, 2021
2 parents 60db5ba + 888c69e commit 35e61b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}}
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 12 additions & 24 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ 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 })
const workflow = core.getInput("workflow", { required: true })
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")
Expand All @@ -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)

Expand All @@ -58,23 +46,23 @@ 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 = {
owner: owner,
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 => {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 35e61b9

Please sign in to comment.