Skip to content

Commit 02abe10

Browse files
committed
chore: fix labeler workflow
1 parent 8ca64a9 commit 02abe10

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

.github/labeler.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
- any-glob-to-any-file:
1111
- '.github/workflows/*'
1212

13-
# Add the `documentation` label to PRs that change any file in the `user_guide_src/source/` directory.
13+
# Add the `documentation` label to PRs for documentation only.
1414
'documentation':
1515
- changed-files:
1616
- any-glob-to-all-files:
17-
- 'user_guide_src/source/*'
17+
- 'user_guide_src/source/**'
1818

19-
# Add the `testing` label to PRs that change files in the `tests/` directory ONLY.
19+
# Add the `testing` label to PRs that changes tests only.
2020
'testing':
2121
- changed-files:
2222
- any-glob-to-all-files:
23-
- 'tests/*'
23+
- 'tests/**'

.github/workflows/label-pr.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,56 @@ name: Add Labels to PRs
44
# in a PR, and then change it back to `pull_request_target` before merging.
55
# @see https://github.com/actions/labeler?tab=readme-ov-file#updating-major-version-of-the-labeler
66
on:
7-
- pull_request_target
7+
- pull_request
88

99
jobs:
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+
1030
add-labels:
31+
needs: validate-source
1132
permissions:
1233
contents: read
1334
pull-requests: write
1435
runs-on: ubuntu-24.04
1536

1637
steps:
38+
- name: Checkout
39+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
40+
41+
- name: Verify PR source for workflow file changes
42+
run: |
43+
# Get changed files in this PR
44+
git fetch origin "refs/pull/${{ github.event.pull_request.number }}/merge"
45+
CHANGED_FILES=$(git diff --name-only origin/develop FETCH_HEAD 2>/dev/null || echo "")
46+
47+
# Check if this workflow file is being modified
48+
if echo "$CHANGED_FILES" | grep -q "\.github/workflows/label-pr\.yml"; then
49+
if [[ "$IS_VALID" != "true" ]]; then
50+
echo "::error::Changes to label-pr.yml can only be made from the main repository."
51+
exit 1
52+
fi
53+
fi
54+
env:
55+
IS_VALID: ${{ needs.validate-source.outputs.valid }}
56+
1757
- name: Add labels
1858
uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
1959
with:

0 commit comments

Comments
 (0)