-
Notifications
You must be signed in to change notification settings - Fork 0
36 lines (30 loc) · 1.26 KB
/
pr-branch-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
name: Check Branch Naming for PRs
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check-branch-naming:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check PR source branch against target branch
run: |
# 获取目标分支和源分支
TARGET_BRANCH="${{ github.base_ref }}"
SOURCE_BRANCH="${{ github.head_ref }}"
echo "Target branch: $TARGET_BRANCH"
echo "Source branch: $SOURCE_BRANCH"
# 检查目标分支是否是 default 分支 (main/master)
if [[ "$TARGET_BRANCH" == "${{ github.event.repository.default_branch }}" ]]; then
if [[ ! "$SOURCE_BRANCH" =~ ^release/.* ]]; then
echo "Error: The source branch must be of the form 'release/*' when merging into the default branch."
exit 1
fi
# 检查目标分支是否是 release/*
elif [[ "$TARGET_BRANCH" =~ ^release/.* ]]; then
if [[ ! "$SOURCE_BRANCH" =~ ^(feature|bugfix)/.* ]]; then
echo "Error: The source branch must be of the form 'feature/*' or 'bugfix/*' when merging into 'release/*'."
exit 1
fi
fi