-
Notifications
You must be signed in to change notification settings - Fork 7
43 lines (39 loc) · 1.21 KB
/
main.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
name: Merge Protection
on:
pull_request:
branches: [main, release, doc]
jobs:
check-branch-rules:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Check branch merge rules
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
base_branch="${{ github.base_ref }}"
head_branch="${{ github.head_ref }}"
case $base_branch in
main)
if [[ $head_branch != "release" && $head_branch != "doc" ]]; then
echo "Error: main can only be merged from release or doc branches."
exit 1
fi
;;
release)
if [[ $head_branch != feature/* ]]; then
echo "Error: release can only be merged from feature/* branches."
exit 1
fi
;;
doc)
echo "Error: doc branch cannot be merged from any other branch."
exit 1
;;
*)
if [[ $head_branch == test/* ]]; then
echo "Error: test/ branches cannot be merged into any other branch."
exit 1
fi
;;
esac