Skip to content

Improve watch script with colored concurrent output #16

Improve watch script with colored concurrent output

Improve watch script with colored concurrent output #16

name: Validate Branch Name
on:
push:
branches:
- '**' # Run on all branch pushes
pull_request:
branches:
- '**' # Run on all PR target branches
jobs:
validate-branch-name:
runs-on: ubuntu-latest
name: Validate Branch Naming Convention
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
sparse-checkout: |
Umbraco.Ai
Umbraco.Ai.*
sparse-checkout-cone-mode: false
- name: Check branch name
run: |
# Get the branch name
if [ "${{ github.event_name }}" == "pull_request" ]; then
BRANCH_NAME="${{ github.head_ref }}"
else
BRANCH_NAME="${{ github.ref_name }}"
fi
echo "Validating branch: $BRANCH_NAME"
# Dynamically discover valid products from directory structure
# Umbraco.Ai/ -> "core"
# Umbraco.Ai.<name>/ -> "<name>" (lowercase)
PRODUCTS=""
for dir in Umbraco.Ai*/; do
if [ -d "$dir" ]; then
dir_name=$(basename "$dir")
if [ "$dir_name" = "Umbraco.Ai" ]; then
PRODUCTS="$PRODUCTS core"
elif [[ "$dir_name" =~ ^Umbraco\.Ai\.(.+)$ ]]; then
product_name="${BASH_REMATCH[1]}"
# Convert to lowercase
PRODUCTS="$PRODUCTS ${product_name,,}"
fi
fi
done
PRODUCTS=$(echo "$PRODUCTS" | xargs) # Trim whitespace
if [ -z "$PRODUCTS" ]; then
echo "ERROR: No Umbraco.Ai products found in repository"
exit 1
fi
echo "Discovered products: $PRODUCTS"
# Allow main and develop branches
if [ "$BRANCH_NAME" == "main" ] || [ "$BRANCH_NAME" == "develop" ]; then
echo "✓ Valid branch: $BRANCH_NAME"
exit 0
fi
# Validate branch name pattern
VALID=false
# Check feature branches: feature/<product>-<description>
if echo "$BRANCH_NAME" | grep -qE "^feature/([a-z]+)-.+"; then
PRODUCT=$(echo "$BRANCH_NAME" | sed -E 's/^feature\/([a-z]+)-.*/\1/')
for p in $PRODUCTS; do
if [ "$PRODUCT" == "$p" ]; then
VALID=true
break
fi
done
fi
# Check release branches: release/<product>-<version>
if echo "$BRANCH_NAME" | grep -qE "^release/([a-z]+)-[0-9]+\.[0-9]+\.[0-9]+"; then
PRODUCT=$(echo "$BRANCH_NAME" | sed -E 's/^release\/([a-z]+)-.*/\1/')
for p in $PRODUCTS; do
if [ "$PRODUCT" == "$p" ]; then
VALID=true
break
fi
done
fi
# Check hotfix branches: hotfix/<product>-<version>
if echo "$BRANCH_NAME" | grep -qE "^hotfix/([a-z]+)-[0-9]+\.[0-9]+\.[0-9]+"; then
PRODUCT=$(echo "$BRANCH_NAME" | sed -E 's/^hotfix\/([a-z]+)-.*/\1/')
for p in $PRODUCTS; do
if [ "$PRODUCT" == "$p" ]; then
VALID=true
break
fi
done
fi
# Report result
if [ "$VALID" == "true" ]; then
echo "✓ Valid branch name: $BRANCH_NAME"
exit 0
else
echo "========================================"
echo "ERROR: Invalid branch name: $BRANCH_NAME"
echo "========================================"
echo ""
echo "Branch names must follow one of these patterns:"
echo " main"
echo " develop"
echo " feature/<product>-<description>"
echo " release/<product>-<version>"
echo " hotfix/<product>-<version>"
echo ""
echo "Valid products: $PRODUCTS"
echo ""
echo "Examples:"
echo " feature/core-add-caching"
echo " release/agent-17.1.0"
echo " hotfix/openai-1.0.1"
echo "========================================"
exit 1
fi