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
11 changes: 11 additions & 0 deletions .github/workflows/caller-pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: 🔍 PR Validation

on:
pull_request:
types: [opened, edited, synchronize, reopened]

jobs:
pr-validation:
uses: ./.github/workflows/pr-checks.yml
...
66 changes: 57 additions & 9 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
name: '🔍 PR Validation'

on:
workflow_call:
inputs:
Expand All @@ -18,44 +19,79 @@ on:
perf
build
revert

requireScope:
required: false
type: boolean
default: false

subjectPattern:
required: false
type: string
default: '^[A-Z].+$'
default: '[A-Za-z].+'

validateSingleCommit:
required: false
type: boolean
default: false

checkLabels:
required: false
type: boolean
default: true

commitlintConfig:
description: "Path to commitlint configuration file"
required: false
type: string
default: "commitlint.config.cjs"

jobs:
validate-title:
name: 📝 Validate PR title
runs-on: ubuntu-latest

steps:
- name: Validate PR title format
run: |
TITLE="${{ github.event.pull_request.title }}"

echo "PR Title: $TITLE"

PATTERN="^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\([a-zA-Z0-9_-]+\))?: .+"
TYPES=$(echo "${{ inputs.types }}" | tr '\n' '|' | sed 's/|$//')

if [[ ! "$TITLE" =~ $PATTERN ]]; then
echo "::error::PR title does not follow Conventional Commits format."
echo "Valid examples:"
# Allow capitalized types as well
TYPES_REGEX="${TYPES}|$(echo ${TYPES} | sed 's/\([^|]*\)/\u\1|\l\1/g')"

# Full regex for conventional commits
FULL_REGEX="^(${TYPES_REGEX})(\([a-zA-Z0-9_-]+\))?:\s+${{ inputs.subjectPattern }}$"

if [[ ! "$TITLE" =~ $FULL_REGEX ]]; then
echo "::error::PR title does not follow Conventional Commit format."
echo ""
echo "Required format:"
echo " type(scope): subject"
echo " type: subject"
echo ""
echo "Examples:"
echo " feat: Add login API"
echo " fix(auth): Resolve token issue"
echo " docs(readme): Update README"
echo ""
echo "Allowed types:"
echo "${{ inputs.types }}"
exit 1
fi

# Enforce scope if required
if [[ "${{ inputs.requireScope }}" == "true" ]]; then
if [[ ! "$TITLE" =~ ^(${TYPES_REGEX})\([a-zA-Z0-9_-]+\): ]]; then
echo "::error::PR title must include a scope because requireScope=true"
echo "Example:"
echo " feat(auth): Add login API"
exit 1
fi
fi

echo "PR title validation passed."

- name: 🏷️ Check PR labels
Expand All @@ -73,14 +109,26 @@ jobs:
validate-commits:
name: 🧾 Validate Commit Messages
runs-on: ubuntu-latest

steps:
- name: 📦 Checkout Repository
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: 🧾 Commitlint Validation (Inline Config)
- name: 🔢 Validate single commit
if: ${{ inputs.validateSingleCommit }}
run: |
COUNT=$(git rev-list --count origin/${{ github.base_ref }}..HEAD)
echo "Commit count in PR: $COUNT"

if [ "$COUNT" -ne 1 ]; then
echo "::error::This PR must contain exactly one commit."
exit 1
fi

- name: 🧾 Commitlint Validation
uses: wagoid/commitlint-github-action@v6
with:
configFile: commitlint.config.cjs
...
configFile: ${{ inputs.commitlintConfig }}
...
1 change: 1 addition & 0 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ jobs:
validateSingleCommit: ${{ inputs.validateSingleCommit }}
checkLabels: ${{ inputs.checkLabels }}
secrets: inherit
...
Loading