77 - pull_request_target
88
99jobs :
10- validate-source :
11- permissions :
12- contents : read
13- pull-requests : read
14- runs-on : ubuntu-24.04
15- outputs :
16- valid : ${{ steps.check.outputs.valid }}
17-
18- steps :
19- - name : Check if PR is from the main repository
20- id : check
21- run : |
22- if [[ "$HEAD_REPO" == "codeigniter4/CodeIgniter4" ]]; then
23- echo "valid=true" >> $GITHUB_OUTPUT
24- else
25- echo "valid=false" >> $GITHUB_OUTPUT
26- fi
27- env :
28- HEAD_REPO : ${{ github.event.pull_request.head.repo.full_name }}
29-
3010 add-labels :
31- needs : validate-source
3211 permissions :
3312 contents : read
3413 pull-requests : write
@@ -41,20 +20,26 @@ jobs:
4120 persist-credentials : false
4221
4322 - name : Verify PR source for workflow file changes
44- run : |
45- # Get changed files in this PR
46- git fetch origin "refs/pull/${{ github.event.pull_request.number }}/merge"
47- CHANGED_FILES=$(git diff --name-only origin/develop FETCH_HEAD 2>/dev/null || echo "")
48-
49- # Check if this workflow file is being modified
50- if echo "$CHANGED_FILES" | grep -q "\.github/workflows/label-pr\.yml"; then
51- if [[ "$IS_VALID" != "true" ]]; then
52- echo "::error::Changes to label-pr.yml can only be made from the main repository."
53- exit 1
54- fi
55- fi
56- env :
57- IS_VALID : ${{ needs.validate-source.outputs.valid }}
23+ uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
24+ with :
25+ script : |
26+ const prFiles = await github.paginate(github.rest.pulls.listFiles.endpoint.merge({
27+ owner: context.repo.owner,
28+ repo: context.repo.repo,
29+ pull_number: context.payload.pull_request.number,
30+ }));
31+ const workflowFileChanged = prFiles.some(file => file.filename === '.github/workflows/label-pr.yml');
32+
33+ if (workflowFileChanged) {
34+ if (context.payload.pull_request.head.repo.full_name !== 'codeigniter4/CodeIgniter4') {
35+ throw new Error('Changes to label-pr.yml are not allowed from forks.');
36+ }
37+
38+ console.log('Workflow file changed, but PR is from the main repository. Proceeding with label addition.');
39+ return;
40+ }
41+
42+ console.log('No changes to workflow file detected, proceeding with label addition.');
5843
5944 - name : Add labels
6045 uses : actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
0 commit comments