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 all 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
3 changes: 3 additions & 0 deletions README.md
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
Expand Up @@ -55,6 +55,10 @@ 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
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
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