SWLDEVOPS-7853 - Action file to mandate branch naming convention (#2)

SWLDEVOPS-7853 - Action file to mandate branch naming convention
---------
Co-authored-by: vkallesh <vkallesh@amd.com>
This commit is contained in:
Kallesh, Vijay-teekinavar
2025-05-14 15:29:35 +05:30
committed by GitHub
parent 42a0d74ced
commit a2a045cb2e

30
.github/workflows/branch-name-check.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: Branch Name Check
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
check_branch_name:
runs-on: Linux # Use the default GitHub-hosted runner with Linux
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Check branch name using Bash
env:
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
USER: ${{ github.actor }}
run: |
echo "Original USER: $USER"
BASE_USER=${USER%_amdeng} # Trim the trailing _amdeng from the USER
echo "Trimmed USER: $BASE_USER"
echo "Checking branch name: $BRANCH_NAME"
if [[ ! "$BRANCH_NAME" =~ ^u/.*/PR/.*$ ]] && [[ ! "$BRANCH_NAME" =~ ^u/.*/WIP/.*$ ]]; then
echo "Error: Branch name '$BRANCH_NAME' does not match the required naming convention 'u/$BASE_USER/PR-*' or 'u/$BASE_USER/WIP-*'."
exit 1
fi
echo "Branch name '$BRANCH_NAME' is valid."
shell: bash # Use the default Linux shell