diff --git a/README.md b/README.md index 982e87f8..aee6421c 100644 --- a/README.md +++ b/README.md @@ -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. + # default true + allow_forks: false ``` diff --git a/action.yml b/action.yml index 66e9d656..27dfcbf0 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/main.js b/main.js index 29a2901d..670d2ae0 100644 --- a/main.js +++ b/main.js @@ -38,8 +38,14 @@ async function main() { let runNumber = core.getInput("run_number") let checkArtifacts = core.getBooleanInput("check_artifacts") let searchArtifacts = core.getBooleanInput("search_artifacts") + let allowForks = core.getBooleanInput("allow_forks") let dryRun = core.getInput("dry_run") + // Using allow_forks lets the user accept any fork, in any situation, + // But if it's not set, we forbid forks if the user is trying to download + // artifacts from a given branch. + const willAcceptForks = allowForks || !branch; + const client = github.getOctokit(token) core.info(`==> Repository: ${owner}/${repo}`) @@ -120,7 +126,7 @@ async function main() { if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) { continue } - if (run.head_repository.full_name !== `${owner}/${repo}`) { + if (!willAcceptForks && run.head_repository.full_name !== `${owner}/${repo}`) { core.info(`==> Skipping run from fork: ${run.head_repository.full_name}`) continue; }