---
name: PR Title Validation
on:
pull_request:
types: [opened, edited, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: read
jobs:
validate-pr-title:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Validate PR title follows Conventional Commits
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "Validating PR title: $PR_TITLE"
echo ""
# Conventional commit regex pattern
# Format: type(scope)?: description
# Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
PATTERN='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-zA-Z0-9_-]+\))?!?: .+'
if [[ "$PR_TITLE" =~ $PATTERN ]]; then
echo "✓ PR title follows Conventional Commits format"
echo ""
echo "Type: ${BASH_REMATCH[1]}"
if [[ -n "${BASH_REMATCH[2]}" ]]; then
echo "Scope: ${BASH_REMATCH[2]}"
fi
exit 0
else
echo "✗ PR title does not follow Conventional Commits format"
echo ""
echo "PR titles must follow the Conventional Commits specification:"
echo " <type>(<scope>): <description>"
echo ""
echo "Types (required):"
echo " feat - A new feature (triggers minor version bump)"
echo " fix - A bug fix (triggers patch version bump)"
echo " docs - Documentation only changes"
echo " style - Code style changes (formatting, semicolons, etc)"
echo " refactor - Code refactoring (no feature or fix)"
echo " perf - Performance improvements"
echo " test - Adding or updating tests"
echo " build - Build system or dependencies"
echo " ci - CI/CD configuration"
echo " chore - Other changes (no production code)"
echo " revert - Reverting a previous commit"
echo ""
echo "Scope (optional):"
echo " A noun describing the section of the codebase"
echo " Examples: api, parser, cli, docs"
echo ""
echo "Breaking changes:"
echo " Add ! after type/scope: feat!: or feat(api)!:"
echo ""
echo "Examples:"
echo " feat: add Chef to Ansible conversion"
echo " fix(parser): handle empty recipe files"
echo " docs: update README with new examples"
echo " feat!: redesign API for v2"
echo " chore(deps): update dependencies"
echo ""
echo "Your title: $PR_TITLE"
exit 1
fi