Skip to content
This repository was archived by the owner on Jul 20, 2026. It is now read-only.

Commit aa7141c

Browse files
Add workflow to restrict merge sources for branches
1 parent d383eab commit aa7141c

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Restrict merge source
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- dev
8+
- docs
9+
10+
jobs:
11+
check-source-branch:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check that PR source is 'dev'
15+
run: |
16+
if [ "${{ github.base_ref }}" == "master" ]; then
17+
if [ "${{ github.head_ref }}" != "dev" ] && [ "${{ github.head_ref }}" != "docs" ]; then
18+
echo "PRs to master are only allowed from the 'dev' or 'docs' branch."
19+
echo "Source branch was: ${{ github.head_ref }}"
20+
exit 1
21+
fi
22+
fi
23+
24+
if [ "${{ github.base_ref }}" == "dev" ] && [ "${{ github.head_ref }}" == "master" ]; then
25+
echo "Merges from 'master' to 'dev' are not allowed."
26+
exit 1
27+
fi
28+
29+
if [ "${{ github.base_ref }}" == "docs" ]; then
30+
echo "No merges are allowed onto 'docs'."
31+
exit 1
32+
fi
33+
34+
if [ "${{ github.head_ref }}" == "docs" ] && [ "${{ github.base_ref }}" != "master" ]; then
35+
echo "'docs' can only be merged into 'master'."
36+
echo "Target branch was: ${{ github.base_ref }}"
37+
exit 1
38+
fi
39+
40+
echo "Source branch is allowed. Proceeding."

0 commit comments

Comments
 (0)