diff --git a/README.md b/README.md index aca4db31..f986aafb 100644 --- a/README.md +++ b/README.md @@ -578,6 +578,9 @@ GoZen automatically migrates configurations from previous versions: ## Development ```sh +# Install Git hooks (branch naming validation) +./scripts/install-hooks.sh + # Build go build -o zen . @@ -585,6 +588,8 @@ go build -o zen . go test ./... ``` +**Branch Naming Convention**: All feature branches must follow the format `/` where type is one of: `feat`, `fix`, `docs`, `refactor`, `test`, `chore`, `perf`, `ci`, `build`, `revert`. Examples: `feat/user-auth`, `fix/payment-bug`. + Release: Push a tag and GitHub Actions will build automatically. ```sh diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh new file mode 100755 index 00000000..be07ea45 --- /dev/null +++ b/scripts/install-hooks.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Install Git hooks for GoZen development + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +HOOKS_DIR="$REPO_ROOT/.git/hooks" + +echo "Installing Git hooks..." + +# Install pre-commit hook +cp "$SCRIPT_DIR/pre-commit-hook.sh" "$HOOKS_DIR/pre-commit" +chmod +x "$HOOKS_DIR/pre-commit" + +echo "✓ Pre-commit hook installed successfully" +echo "" +echo "Branch naming format: /" +echo "Allowed types: feat, fix, docs, refactor, test, chore, perf, ci, build, revert" +echo "" +echo "Examples:" +echo " - feat/user-authentication" +echo " - fix/payment-processing-bug" +echo " - docs/api-documentation" diff --git a/scripts/pre-commit-hook.sh b/scripts/pre-commit-hook.sh new file mode 100755 index 00000000..b17c3f9b --- /dev/null +++ b/scripts/pre-commit-hook.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Pre-commit hook to validate branch names +# Format: / +# Allowed types: feat, fix, docs, refactor, test, chore, perf, ci, build, revert + +# Get current branch name +branch=$(git rev-parse --abbrev-ref HEAD) + +# Protected branches (skip validation) +if [ "$branch" = "main" ] || [ "$branch" = "master" ] || [ "$branch" = "develop" ]; then + exit 0 +fi + +# Skip validation during rebase/merge +if [ -d .git/rebase-merge ] || [ -d .git/rebase-apply ] || [ -f .git/MERGE_HEAD ]; then + exit 0 +fi + +# Validate branch name format +valid_pattern="^(feat|fix|docs|refactor|test|chore|perf|ci|build|revert)/[a-z0-9-]+$" + +if ! echo "$branch" | grep -qE "$valid_pattern"; then + echo "" + echo "❌ Branch name validation failed" + echo "" + echo "Branch: $branch" + echo "" + echo "Error: Branch name does not match the required pattern: /" + echo "" + echo "Valid branch name format: /" + echo "Allowed types: feat, fix, docs, refactor, test, chore, perf, ci, build, revert" + echo "" + echo "Examples:" + echo " - feat/user-authentication" + echo " - fix/payment-processing-bug" + echo " - docs/api-documentation" + echo "" + exit 1 +fi + +exit 0