-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (39 loc) · 1.33 KB
/
branch-status-check.yml
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
name: Branch Naming Check
on:
push:
branches:
- '**' # Trigger on any push to any branch
pull_request:
branches:
- '**' # Trigger on PR creation
jobs:
check-naming-convention:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Check branch name
run: |
if [ "${{ github.event_name }}" == "push" ]; then
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
elif [ "${{ github.event_name }}" == "pull_request" ]; then
BRANCH_NAME="${GITHUB_HEAD_REF}"
else
echo "Unsupported event: ${{ github.event_name }}"
exit 1
fi
echo "Checking branch name: $BRANCH_NAME"
# Define allowed naming patterns (Regex for feature, bugfix, etc.)
if [[ ! "$BRANCH_NAME" =~ ^(main|feature/.*|chore/.*|bugfix/.*|hotfix/.*|dependabot/.*|security/.*|dev)$ ]]; then
echo "Error: Invalid branch name '$BRANCH_NAME'. It must follow one of the following patterns:"
echo "- main"
echo "- feature/*"
echo "- chore/*"
echo "- bugfix/*"
echo "- hotfix/*"
echo "- dependabot/*"
echo "- security/*"
echo "- dev"
exit 1
fi
echo "Branch name is valid."