-
Notifications
You must be signed in to change notification settings - Fork 0
36 lines (31 loc) · 1.11 KB
/
check-branch.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
name: Check Branch Name and Prevent Main Merge
on:
pull_request:
branches:
- dev
- main
jobs:
check-branch-name:
runs-on: ubuntu-latest
if: github.event.pull_request.base.ref == 'dev'
steps:
- name: Extract Source Branch Name
run: |
branch_name=$(jq -r .pull_request.head.ref "$GITHUB_EVENT_PATH")
echo "Source Branch: $branch_name"
if [[ ! $branch_name =~ ^(feat/[0-9]+|bug/[0-9]+|refactor/[0-9]+|hotfix_[0-9]{4}|chore_[0-9]{4}|gh-pages)$ ]]; then
echo "Error: Branch name must follow the pattern 'feat/[number]', 'bug/[number]', 'hotfix_mmdd', 'chore_mmdd', or 'gh-pages'."
exit 1
fi
prevent-main-merge:
runs-on: ubuntu-latest
if: github.event.pull_request.base.ref == 'main'
steps:
- name: Prevent Merge to Main
run: |
base_branch=$(jq -r .pull_request.base.ref "$GITHUB_EVENT_PATH")
echo "Base Branch: $base_branch"
if [[ $base_branch == "main" ]]; then
echo "Error: Pull requests to the main branch are not allowed."
exit 1
fi