From a8e5348892173953ed3634bf8a1d0694abc041f0 Mon Sep 17 00:00:00 2001 From: Andrew Lamkin Date: Thu, 20 Nov 2025 22:36:19 +0000 Subject: [PATCH] Workflow for merge protection for specific named branches --- .github/workflows/branch-name-check.yml | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/branch-name-check.yml diff --git a/.github/workflows/branch-name-check.yml b/.github/workflows/branch-name-check.yml new file mode 100644 index 0000000..4f2612c --- /dev/null +++ b/.github/workflows/branch-name-check.yml @@ -0,0 +1,61 @@ +name: Branch Name Check + +on: + pull_request: + types: [opened, synchronize, reopened, edited] + branches: + - main + - dev + - 'client-*' + +jobs: + check-branch-name: + runs-on: ubuntu-latest + steps: + - name: Check branch name for main + if: github.base_ref == 'main' + run: | + BRANCH_NAME="${{ github.head_ref }}" + echo "Source branch: $BRANCH_NAME" + echo "Target branch: ${{ github.base_ref }}" + + if [[ $BRANCH_NAME == dev ]] || [[ $BRANCH_NAME == hotfix-* ]]; then + echo "Branch name is valid" + exit 0 + else + echo "Invalid branch name for main pull request" + echo "Branch name must be dev or start with 'hotfix-'" + exit 1 + fi + + - name: Check branch name for dev + if: github.base_ref == 'dev' + run: | + BRANCH_NAME="${{ github.head_ref }}" + echo "Source branch: $BRANCH_NAME" + echo "Target branch: ${{ github.base_ref }}" + + if [[ $BRANCH_NAME == hotfix-* ]] || [[ $BRANCH_NAME == feature-* ]] || [[ $BRANCH_NAME == bugfix-* ]]; then + echo "Branch name is valid" + exit 0 + else + echo "Invalid branch name for dev pull request" + echo "Branch name must start with 'hotfix-', 'feature-', or 'bugfix-'" + exit 1 + fi + + - name: Check branch name for client branches + if: startsWith(github.base_ref, 'client-') + run: | + BRANCH_NAME="${{ github.head_ref }}" + echo "Source branch: $BRANCH_NAME" + echo "Target branch: ${{ github.base_ref }}" + + if [[ $BRANCH_NAME == feature-* ]] || [[ $BRANCH_NAME == bugfix-* ]] || [[ $BRANCH_NAME == hotfix-* ]]; then + echo "Branch name is valid" + exit 0 + else + echo "Invalid branch name for client pull request" + echo "Branch name must start with 'feature-', 'bugfix-', or 'hotfix-'" + exit 1 + fi \ No newline at end of file