Skip to content

Commit d376cb3

Browse files
authored
Use path event trigger
1 parent 891b9bd commit d376cb3

File tree

1 file changed

+7
-31
lines changed

1 file changed

+7
-31
lines changed
Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
11
name: PR Workflow Check
22

33
on:
4-
pull_request_target: ~
4+
pull_request_target:
5+
paths:
6+
- ".github/**"
57

68
jobs:
79
check:
10+
if: ${{ github.event.pull_request.head.repo.fork }}
811
runs-on: ubuntu-latest
912
steps:
10-
- name: Checkout merge commit
11-
uses: actions/checkout@v4
12-
with:
13-
ref: "refs/pull/${{ github.event.number }}/merge"
14-
fetch-depth: 2
15-
16-
- name: Check changes to .github
17-
if: ${{ github.event.pull_request.head.repo.fork }}
18-
id: check
19-
run: |
20-
echo "==> Changed files:"
21-
git diff --name-only HEAD^1 HEAD
22-
count=$(git diff --name-only HEAD^1 HEAD | grep -c '^\.github/') || count=0
23-
24-
if [[ $count -gt 0 ]]; then
25-
echo "==> Found $count violations!"
26-
echo "==> Violating files"
27-
git diff --name-only HEAD^1 HEAD | grep '^\.github/' || echo "--None--"
28-
echo "::error::PR is trying to change a workflow!"
29-
echo "bad=true" >> "$GITHUB_OUTPUT"
30-
exit 1
31-
else
32-
echo "All OK"
33-
echo "bad=false" >> "$GITHUB_OUTPUT"
34-
fi
35-
3613
- name: Comment PR
37-
if: ${{ always() && github.event.pull_request.head.repo.fork && steps.check.outputs.bad == 'true' }}
3814
uses: actions/github-script@v7
3915
with:
4016
script: |
@@ -47,6 +23,6 @@ jobs:
4723
> Proceed with caution and if not sure, contact your GitHub admin.`
4824
})
4925
50-
- if: ${{ !github.event.pull_request.head.repo.fork }}
51-
run: |
52-
echo "Not a PR from fork."
26+
- run: |
27+
::error::PR originating from a fork changes a Github workflow!
28+
exit 1

0 commit comments

Comments
 (0)