Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore forks #250

Merged
merged 6 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ 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
# when a branch is specified, this is defaulted to false.
laurentsenta marked this conversation as resolved.
Show resolved Hide resolved
# default true
allow_forks: false
```
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ inputs:
description: Where to unpack the artifact
required: false
default: "./"
allow_forks:
description: Allow forks
required: false
laurentsenta marked this conversation as resolved.
Show resolved Hide resolved
check_artifacts:
description: Check workflow run whether it has an artifact
required: false
Expand Down
15 changes: 15 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")
let hasAllowForksInput = core.getInput("allow_forks") !== ""
laurentsenta marked this conversation as resolved.
Show resolved Hide resolved
let dryRun = core.getInput("dry_run")

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

// We allow forks by default, except when a branch is requested
let allowForks = !branch

// `allow_forks` overrides any other logic
if (hasAllowForksInput) {
allowForks = core.getBooleanInput("allow_forks")
}

laurentsenta marked this conversation as resolved.
Show resolved Hide resolved
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 +131,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