Skip to content

Commit a2a045c

Browse files
authored
SWLDEVOPS-7853 - Action file to mandate branch naming convention (#2)
SWLDEVOPS-7853 - Action file to mandate branch naming convention --------- Co-authored-by: vkallesh <[email protected]>
1 parent 42a0d74 commit a2a045c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Branch Name Check
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
check_branch_name:
9+
runs-on: Linux # Use the default GitHub-hosted runner with Linux
10+
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@v2
14+
15+
- name: Check branch name using Bash
16+
env:
17+
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
18+
USER: ${{ github.actor }}
19+
run: |
20+
echo "Original USER: $USER"
21+
BASE_USER=${USER%_amdeng} # Trim the trailing _amdeng from the USER
22+
echo "Trimmed USER: $BASE_USER"
23+
24+
echo "Checking branch name: $BRANCH_NAME"
25+
if [[ ! "$BRANCH_NAME" =~ ^u/.*/PR/.*$ ]] && [[ ! "$BRANCH_NAME" =~ ^u/.*/WIP/.*$ ]]; then
26+
echo "Error: Branch name '$BRANCH_NAME' does not match the required naming convention 'u/$BASE_USER/PR-*' or 'u/$BASE_USER/WIP-*'."
27+
exit 1
28+
fi
29+
echo "Branch name '$BRANCH_NAME' is valid."
30+
shell: bash # Use the default Linux shell

0 commit comments

Comments
 (0)