Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/branch-naming.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Enforcing Branch Naming Convention

name: Branch Naming Convention

on: create

permissions:
contents: write

jobs:
check-branch-name:
runs-on: ubuntu-latest
steps:
- name: Check branch name
run: |
BRANCH="${{ github.ref_name }}"

# Branches exempt from naming rules
EXEMPT="^(main|dev|dev-stage|staging|develop)$"
if echo "$BRANCH" | grep -Eq "$EXEMPT"; then
echo "✅ Exempt branch '$BRANCH' — skipping check"
exit 0
fi

# Your naming convention regex
PATTERN="^(fe|be|infra|config)\/(feat|fix|hotfix|docs|refactor|chore|release)\/[a-z0-9][a-z0-9\-]+$"

if echo "$BRANCH" | grep -Eq "$PATTERN"; then
echo "✅ Branch name '$BRANCH' is valid"
else
echo "❌ Branch name '$BRANCH' does not match naming convention"
echo ""
echo "Expected format: <area>/<type>/<descriptor>"
echo "Areas: fe | be | infra | config"
echo "Types: feat | fix | hotfix | docs | refactor | chore | release"
echo "Example: fe/feat/ed-110 or be/fix/ed-45"
echo ""
echo "Deleting invalid branch..."
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
gh api -X DELETE "repos/${{ github.repository }}/git/refs/heads/$(python3 -c 'import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))' "$BRANCH")"
exit 1
fi
Loading
Loading