diff --git a/.github/workflows/crucible-ci.yaml b/.github/workflows/crucible-ci.yaml index 1bb268e..eb47588 100644 --- a/.github/workflows/crucible-ci.yaml +++ b/.github/workflows/crucible-ci.yaml @@ -27,13 +27,14 @@ jobs: .github/workflows/run-crucible-tracking.yaml .github/workflows/crucible-merged.yaml .github/workflows/crucible-ci.yaml + .github/workflows/fork-check.yaml docs/** - name: Display changes run: echo '${{ toJSON(steps.filter.outputs) }}' | jq . call-real-tool-crucible-ci: needs: changes - if: ${{ github.event_name == 'workflow_dispatch' || needs.changes.outputs.only-docs != 'true' }} + if: ${{ github.event.pull_request.head.repo.fork != true && (github.event_name == 'workflow_dispatch' || needs.changes.outputs.only-docs != 'true') }} uses: perftool-incubator/crucible-ci/.github/workflows/tool-crucible-ci.yaml@main with: ci_target: "sysstat" @@ -45,7 +46,7 @@ jobs: call-faux-tool-crucible-ci: needs: changes - if: ${{ github.event_name != 'workflow_dispatch' && needs.changes.outputs.only-docs == 'true' }} + if: ${{ github.event.pull_request.head.repo.fork != true && github.event_name != 'workflow_dispatch' && needs.changes.outputs.only-docs == 'true' }} uses: perftool-incubator/crucible-ci/.github/workflows/faux-tool-crucible-ci.yaml@main crucible-ci-complete: diff --git a/.github/workflows/fork-check.yaml b/.github/workflows/fork-check.yaml new file mode 100644 index 0000000..2934d35 --- /dev/null +++ b/.github/workflows/fork-check.yaml @@ -0,0 +1,27 @@ +name: fork-check + +on: + pull_request_target: + types: [opened, reopened] + +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' + });