Skip to content

Commit 2686771

Browse files
fix: ignore forks (#250)
* 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]>
1 parent 079ae9a commit 2686771

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,7 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
7272
# "fail", "warn", "ignore"
7373
# default fail
7474
if_no_artifact_found: fail
75+
# Optional, ignore forks when searching for artifacts
76+
# default true
77+
allow_forks: false
7578
```

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ inputs:
5555
description: Where to unpack the artifact
5656
required: false
5757
default: "./"
58+
allow_forks:
59+
description: Allow forks
60+
required: false
61+
default: true
5862
check_artifacts:
5963
description: Check workflow run whether it has an artifact
6064
required: false

main.js

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async function main() {
3838
let runNumber = core.getInput("run_number")
3939
let checkArtifacts = core.getBooleanInput("check_artifacts")
4040
let searchArtifacts = core.getBooleanInput("search_artifacts")
41+
const allowForks = core.getBooleanInput("allow_forks")
4142
let dryRun = core.getInput("dry_run")
4243

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

106+
core.info(`==> Allow forks: ${allowForks}`)
107+
105108
if (!runID) {
106109
// Note that the runs are returned in most recent first order.
107110
for await (const runs of client.paginate.iterator(client.rest.actions.listWorkflowRuns, {
@@ -120,6 +123,10 @@ async function main() {
120123
if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) {
121124
continue
122125
}
126+
if (!allowForks && run.head_repository.full_name !== `${owner}/${repo}`) {
127+
core.info(`==> Skipping run from fork: ${run.head_repository.full_name}`)
128+
continue
129+
}
123130
if (checkArtifacts || searchArtifacts) {
124131
let artifacts = await client.paginate(client.rest.actions.listWorkflowRunArtifacts, {
125132
owner: owner,

0 commit comments

Comments
 (0)