Merge branch 'develop' of github.com:SDNNetSim/FUSION into develop #1166
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Latest Commit Message Validation | |
| on: | |
| pull_request: | |
| branches: | |
| - develop | |
| - main | |
| - 'release/**' | |
| types: | |
| - opened | |
| - edited | |
| - reopened | |
| - synchronize | |
| pull_request_target: | |
| branches: | |
| - develop | |
| - main | |
| - 'release/**' | |
| types: | |
| - opened | |
| - edited | |
| - reopened | |
| - synchronize | |
| push: | |
| branches: | |
| - develop | |
| - main | |
| - 'release/**' | |
| jobs: | |
| validate_commit_messages: | |
| name: Validate Latest Commit Message | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Debug commit information | |
| run: | | |
| echo "=== DEBUG: Commit info ===" | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "PR event - checking latest commit only" | |
| echo "Latest commit: ${{ github.event.pull_request.head.sha }}" | |
| echo "Latest commit message:" | |
| git log --format="%B" -n 1 ${{ github.event.pull_request.head.sha }} | |
| else | |
| echo "Push event - checking pushed commit" | |
| echo "HEAD commit: $(git rev-parse HEAD)" | |
| echo "HEAD commit message:" | |
| git log --format="%B" -n 1 HEAD | |
| fi | |
| echo "=== End Debug ===" | |
| - name: Validate commit messages with custom script | |
| run: | | |
| #!/bin/bash | |
| set -e | |
| echo "=== Custom Commit Message Validation ===" | |
| # Enhanced validation for conventional commits | |
| # Allow detailed commit bodies while enforcing subject line format | |
| validate_commit() { | |
| local commit_sha="$1" | |
| local subject_line="$2" | |
| # Check if this is a merge commit - these have different rules | |
| local MERGE_PATTERN='^Merge (branch|pull request|remote-tracking branch)' | |
| if echo "$subject_line" | grep -qE "$MERGE_PATTERN"; then | |
| return 0 # Pass silently for merge commits | |
| fi | |
| # Pattern for conventional commit subject line | |
| # - Type is required | |
| # - Scope is optional | |
| # - Description must be at least 5 chars, max 100 for entire subject line | |
| # - Use imperative mood (no period at end) | |
| # - Allow upper or lowercase start (for acronyms like CLI, API, etc.) | |
| local SUBJECT_PATTERN='^(feat|fix|docs|style|refactor|perf|test|chore|build|ci)(\(.+\))?: [a-zA-Z].{4,}[^.]$' | |
| # Check subject line length (entire line should be <= 100 chars) | |
| if [ ${#subject_line} -gt 100 ]; then | |
| echo "❌ COMMIT $commit_sha FAILED:" | |
| echo " Subject: '$subject_line'" | |
| echo " Error: Subject line too long (${#subject_line} chars, max 100)" | |
| echo "" | |
| return 1 | |
| fi | |
| # Check subject line format | |
| if echo "$subject_line" | grep -qE "$SUBJECT_PATTERN"; then | |
| return 0 # Pass silently | |
| else | |
| echo "❌ COMMIT $commit_sha FAILED:" | |
| echo " Subject: '$subject_line'" | |
| echo " Error: Subject line does not match conventional commit format" | |
| echo "" | |
| return 1 | |
| fi | |
| } | |
| # Get commits to validate | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| echo "Validating latest commit in PR: ${{ github.event.pull_request.head.sha }}" | |
| echo "" | |
| # Only validate the latest commit (HEAD of the PR branch) | |
| commit_sha="${{ github.event.pull_request.head.sha }}" | |
| commit_msg=$(git log --format="%s" -n 1 "$commit_sha") | |
| echo "Latest commit: $commit_sha" | |
| echo "Message: '$commit_msg'" | |
| echo "" | |
| if validate_commit "$commit_sha" "$commit_msg"; then | |
| echo "✅ Latest commit message is valid!" | |
| else | |
| echo "" | |
| echo "📋 Required Format: <type>(scope): <description>" | |
| echo "" | |
| echo "Optional detailed body and footer are allowed below the subject line." | |
| echo "Merge commits (starting with 'Merge branch/pull request') are automatically valid." | |
| echo "" | |
| echo "🏷️ Valid Types:" | |
| echo "• feat - New feature" | |
| echo "• fix - Bug fix" | |
| echo "• docs - Documentation changes" | |
| echo "• style - Code style changes (formatting, etc.)" | |
| echo "• refactor - Code refactoring" | |
| echo "• perf - Performance improvements" | |
| echo "• test - Adding or updating tests" | |
| echo "• chore - Maintenance tasks" | |
| echo "• build - Build system changes" | |
| echo "• ci - CI/CD changes" | |
| echo "" | |
| echo "📏 Subject Line Requirements:" | |
| echo "• Total length: ≤100 characters" | |
| echo "• Description: ≥5 characters" | |
| echo "• Start with letter after colon (upper/lowercase both OK)" | |
| echo "• No trailing period" | |
| echo "• Be descriptive and clear" | |
| echo "" | |
| echo "✅ Good Examples:" | |
| echo " feat(cli): add configuration validation" | |
| echo " fix(routing): resolve path calculation bug" | |
| echo " refactor(gui): CLI integration for entry point" | |
| echo " docs: update installation guide with new requirements" | |
| echo "" | |
| echo "💡 Tip: Only the latest commit in your PR is checked." | |
| echo " Use 'git commit --amend' to fix the message, or" | |
| echo " 'git rebase -i' to edit older commits if needed." | |
| echo "" | |
| exit 1 | |
| fi | |
| else | |
| # Push event - validate the pushed commit | |
| echo "Validating push commit" | |
| commit_sha=$(git rev-parse HEAD) | |
| commit_msg=$(git log --format="%s" -n 1 HEAD) | |
| if validate_commit "$commit_sha" "$commit_msg"; then | |
| echo "✅ Commit message is valid!" | |
| else | |
| exit 1 | |
| fi | |
| fi |