Skip to content

Commit

Permalink
support event input
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidd6 committed Apr 25, 2021
1 parent 674cbce commit 9cc958d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
commit: ${{github.event.pull_request.head.sha}}
# Optional, will use the branch
branch: master
# Optional, defaults to all types
event: push
# Optional, will use specified workflow run
run_id: 1122334455
# Optional, run number from the workflow
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ inputs:
branch:
description: Branch name
required: false
event:
description: Event type
required: false
run_id:
description: Workflow run id
required: false
Expand Down
17 changes: 9 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ async function main() {
let pr = core.getInput("pr")
let commit = core.getInput("commit")
let branch = core.getInput("branch")
let event = core.getInput("event")
let runID = core.getInput("run_id")
let runNumber = core.getInput("run_number")

const client = github.getOctokit(token)

if ([runID, branch, pr, commit].filter(elem => elem).length > 1) {
throw new Error("don't specify `run_id`, `branch`, `pr`, `commit` together")
}

console.log("==> Workflow:", workflow)

console.log("==> Repo:", owner + "/" + repo)
Expand All @@ -51,20 +48,24 @@ async function main() {
console.log("==> Branch:", branch)
}

if (event) {
console.log("==> Event:", event)
}

if (runNumber) {
console.log("==> RunNumber:", runNumber)
}

if (!runID) {
const endpoint = "GET /repos/:owner/:repo/actions/workflows/:id/runs?status=:status&branch=:branch"
const params = {
for await (const runs of client.paginate.iterator(client.actions.listWorkflowRuns, {
owner: owner,
repo: repo,
id: workflow,
branch: branch,
event: event,
status: workflowConclusion,
}
for await (const runs of client.paginate.iterator(endpoint,params)) {
)) {
const run = runs.data.find(r => {
if (commit) {
return r.head_sha == commit
Expand Down Expand Up @@ -107,7 +108,7 @@ async function main() {

const size = filesize(artifact.size_in_bytes, { base: 10 })

console.log("==> Downloading:", artifact.name + ".zip", `(${size})`)
console.log(`==> Downloading: ${artifact.name}.zip (${size})`)

const zip = await client.actions.downloadArtifact({
owner: owner,
Expand Down

0 comments on commit 9cc958d

Please sign in to comment.