Skip to content

Commit e797bbd

Browse files
committed
chore(ci-cd): refactor the branch enforcement workflow
1 parent 7db58bf commit e797bbd

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

.github/workflows/branch-check.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@ name: Check Source Branch
22
on:
33
pull_request:
44
branches:
5-
- main
5+
- prod
6+
types:
7+
- opened
8+
- synchronize
9+
- reopened
10+
- edited
611
jobs:
7-
check-branch:
12+
check-source-branch:
13+
name: check-source-branch
814
runs-on: ubuntu-latest
915
steps:
10-
- name: Verify source branch is 'develop'
16+
- name: Check source branch
1117
run: |
12-
if [[ "${{ github.head_ref }}" != "develop" ]]; then
13-
echo "Error: Pull request must come from the 'develop' branch"
18+
HEAD_BRANCH="${{ github.head_ref }}"
19+
BASE_BRANCH="${{ github.base_ref }}"
20+
21+
echo "PR: ${HEAD_BRANCH} → ${BASE_BRANCH}"
22+
23+
if [ "$BASE_BRANCH" = "prod" ] && [ "$HEAD_BRANCH" != "develop" ]; then
24+
echo "::error::Merging to 'prod' is only allowed from the 'develop' branch."
25+
echo "::error::Source branch '${HEAD_BRANCH}' is not permitted."
1426
exit 1
15-
fi
27+
fi
28+
29+
echo "✅ Source branch '${HEAD_BRANCH}' is allowed to merge into '${BASE_BRANCH}'."

0 commit comments

Comments
 (0)