diff --git a/.github/workflows/fork-check.yaml b/.github/workflows/fork-check.yaml new file mode 100644 index 0000000..261f072 --- /dev/null +++ b/.github/workflows/fork-check.yaml @@ -0,0 +1,31 @@ +name: fork-check + +on: + pull_request_target: + types: [opened, reopened, synchronize, edited] + +permissions: + issues: write + pull-requests: write + +jobs: + block-fork-pr: + if: github.event.pull_request.head.repo.fork == true + runs-on: ubuntu-latest + steps: + - name: Comment and close fork PR + uses: actions/github-script@v7 + with: + script: | + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: 'This PR was opened from a fork. PRs must be opened from branches on the upstream repository so that CI workflows have access to required secrets and variables.\n\nPlease push your branch to this repository and open a new PR.\n\nClosing this PR automatically.' + }); + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + state: 'closed' + });