-
Notifications
You must be signed in to change notification settings - Fork 4
55 lines (45 loc) · 1.63 KB
/
Copy pathpr-target-guard.yml
File metadata and controls
55 lines (45 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: PR Target Branch Guard
on:
pull_request:
types: [opened, reopened, synchronize, edited, labeled, unlabeled]
permissions:
contents: read
pull-requests: write
issues: write
jobs:
check-target-branch:
name: Check Target Branch
runs-on: ubuntu-latest
steps:
- name: Validate base branch
id: check
run: |
echo "Base branch is: ${{ github.event.pull_request.base.ref }}"
HAS_RELEASE_LABEL=false
for label in ${{ join(github.event.pull_request.labels.*.name, ' ') }}; do
if [ "$label" = "release" ]; then
HAS_RELEASE_LABEL=true
fi
done
echo "Has release label: $HAS_RELEASE_LABEL"
if [ "${{ github.event.pull_request.base.ref }}" = "main" ] && [ "$HAS_RELEASE_LABEL" != "true" ]; then
echo "WARN=true" >> "$GITHUB_OUTPUT"
else
echo "WARN=false" >> "$GITHUB_OUTPUT"
fi
- name: Comment warning on PR
if: steps.check.outputs.WARN == 'true'
uses: actions/github-script@v8
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: "⚠️ This PR targets **main** but does not have the **release** label. Regular PRs should target **dev**."
});
- name: Fail if targeting main without release label
if: steps.check.outputs.WARN == 'true'
run: |
echo "PRs should target dev unless they are release PRs."
exit 1