Skip to content

Commit

Permalink
fix: ignore forks (#250)
Browse files Browse the repository at this point in the history
* fix: ignore forks

* fix: second pass, add parameters

* style: adapt to local

* fix: defaulting

* fix: naming

* Apply suggestions from code review

Co-authored-by: Dawid Dziurla <[email protected]>

---------

Co-authored-by: Dawid Dziurla <[email protected]>
  • Loading branch information
laurentsenta and dawidd6 authored Sep 18, 2023
1 parent 079ae9a commit 2686771
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
# "fail", "warn", "ignore"
# default fail
if_no_artifact_found: fail
# Optional, ignore forks when searching for artifacts
# default true
allow_forks: false
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ inputs:
description: Where to unpack the artifact
required: false
default: "./"
allow_forks:
description: Allow forks
required: false
default: true
check_artifacts:
description: Check workflow run whether it has an artifact
required: false
Expand Down
7 changes: 7 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async function main() {
let runNumber = core.getInput("run_number")
let checkArtifacts = core.getBooleanInput("check_artifacts")
let searchArtifacts = core.getBooleanInput("search_artifacts")
const allowForks = core.getBooleanInput("allow_forks")
let dryRun = core.getInput("dry_run")

const client = github.getOctokit(token)
Expand Down Expand Up @@ -102,6 +103,8 @@ async function main() {
core.info(`==> Run number: ${runNumber}`)
}

core.info(`==> Allow forks: ${allowForks}`)

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, {
Expand All @@ -120,6 +123,10 @@ async function main() {
if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) {
continue
}
if (!allowForks && run.head_repository.full_name !== `${owner}/${repo}`) {
core.info(`==> Skipping run from fork: ${run.head_repository.full_name}`)
continue
}
if (checkArtifacts || searchArtifacts) {
let artifacts = await client.paginate(client.rest.actions.listWorkflowRunArtifacts, {
owner: owner,
Expand Down

0 comments on commit 2686771

Please sign in to comment.