diff --git a/.github/workflows/validate-pr-title.yml b/.github/workflows/validate-pr-title.yml new file mode 100644 index 0000000..a759afe --- /dev/null +++ b/.github/workflows/validate-pr-title.yml @@ -0,0 +1,38 @@ +name: "Validate PR Title" + +on: + pull_request: + types: [ opened, edited, reopened, ready_for_review, synchronize ] + +jobs: + validate-pr-title: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - name: Check PR title format + shell: bash + run: | + TITLE="${{ github.event.pull_request.title }}" + echo "PR title: $TITLE" + + # Skip validation for renovate + if [[ "$TITLE" == *"chore(deps)"* ]]; then + echo "⚠️ Skipping validation for renovate Prs." + exit 0 + fi + + # Regex for: + # [category/subcategory] type(scope?): description (#123?) + PATTERN='^\[([a-z]+(/[a-z]+)*)\] (feat|fix|chore|docs|style|refactor|perf|test|build|ci|revert)(\([a-z]+\))?: [a-z].*( \(#[0-9]+\))$' + + if [[ ! "$TITLE" =~ $PATTERN ]]; then + echo "❌ Invalid PR title." + echo "Required format:" + echo "[category] type(scope?): description (#123)" + exit 1 + fi + + echo "✅ PR title is valid." \ No newline at end of file