-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull--prevent-wrong-branch-names.yaml
More file actions
44 lines (38 loc) · 1.34 KB
/
pull--prevent-wrong-branch-names.yaml
File metadata and controls
44 lines (38 loc) · 1.34 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
name: Enforce branch naming
# Enforces that a branch is named after a conventional commit type. For example
# the branches: `feat/**`, `fix/**`, ... are allowed but `this is a test` is
# not allowed.
on:
pull_request:
branches: [main, master, release, development]
types: [opened]
jobs:
labeler:
name: Checking branch
runs-on: ubuntu-latest
if: github.event.pull_request.user.login != 'dependabot[bot]'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check branch name compare to types
run: |
branch="${{ github.head_ref }}"
# Extract allowed branch prefixes from labeler.yml where type: true
allowed_branch_names=$(yq '.[] | select(.type == true) | .name' .github/labels.yaml)
echo "Checking branch: $branch"
echo "Allowed branch prefixes are:"
echo "$allowed_branch_names"
echo ""
match_found=0
for pattern in $allowed_branch_names; do
pattern=$(echo "$pattern" | sed 's|\\\\/|/|g' | sed 's|\"||g')
if [[ "$branch" =~ ^$pattern(/.*)?$ ]]; then
echo "Branch name matches allowed pattern: $pattern"
match_found=1
break
fi
done
if [[ $match_found -eq 0 ]]; then
echo "Branch name does not match any allowed pattern!"
exit 1
fi