diff --git a/.github/workflows/pr-title-validation.yml b/.github/workflows/pr-title-validation.yml new file mode 100644 index 00000000..06a92007 --- /dev/null +++ b/.github/workflows/pr-title-validation.yml @@ -0,0 +1,32 @@ +--- +name: PR Title Validation +on: + workflow_call: + inputs: + regex: + description: "Regex to validate PR title" + required: false + type: string + default: '^(Feat:|feat:|Fix:|fix:|Docs:|docs:|Test:|test:|ci:|refactor:|chore:|revert:) ' + +jobs: + pr-title-check: + runs-on: ubuntu-latest + + steps: + - name: Validate PR title + run: | + echo "PR Title: '${{ github.event.pull_request.title }}'" + + TITLE="${{ github.event.pull_request.title }}" + REGEX="${{ inputs.regex }}" + + if [[ ! "$TITLE" =~ $REGEX ]]; then + echo "::error::Invalid PR title." + echo "::error::Title must start with one of:" + echo "::error::Feat:, feat:, Fix:, fix:, Docs:, docs:, Test:, test:, ci:, refactor:, chore:, revert:" + exit 1 + fi + + echo "PR title is valid ✅"[PR Title Validation Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/.github/workflows/pr-title-validation.yml) +... diff --git a/docs/31.pr-title-validation.md b/docs/31.pr-title-validation.md new file mode 100644 index 00000000..31bf8f8a --- /dev/null +++ b/docs/31.pr-title-validation.md @@ -0,0 +1,82 @@ +## [PR Title Validation Workflow](https://github.com/clouddrove/github-shared-workflows/blob/master/.github/workflows/pr-title-validation.yml) + +This workflow is used to **validate Pull Request titles** using GitHub Actions. +It enforces a standardized PR title format (for example: `feat:`, `fix:`, `docs:`) to maintain consistency across repositories. + +## Usage + +The PR Title Validation workflow is automatically triggered on Pull Request events such as: + +- opened +- edited +- synchronized +- reopened + +To use this shared workflow, add the following workflow definition to your repository: + +``` +.github/workflows/pr-title-validation.yml +``` + +--- + +## Example Usage + +```yaml +name: PR Validation + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + +jobs: + pr-title-validation: + uses: clouddrove/github-shared-workflows/.github/workflows/pr-title-validation.yml@master + +``` + +--- + +## Example with Custom Regex (Optional) + +You can override the default PR title regex if your repository follows a different convention (for example, enforcing JIRA tickets). + +```yaml +name: PR Validation + +on: + pull_request: + types: [opened, edited, synchronize, reopened] + +jobs: + pr-title-validation: + uses: clouddrove/github-shared-workflows/.github/workflows/pr-title-validation.yml@master + with: + regex: '^(feat|fix|docs|chore|refactor|ci|test)\([A-Z]+-[0-9]+\): ' + +``` + +### Example Valid PR Titles + +``` +feat: add user login flow +fix: resolve memory leak +docs: update README + +``` + +--- + +## Inputs + +| Name | Required | Description | +| --- | --- | --- | +| `regex` | ❌ No | Custom regex to validate PR title format. If not provided, the default prefix-based regex is used. | + +--- + +## Behavior + +- ✅ If the PR title matches the regex → workflow passes +- ❌ If the PR title does **not** match → workflow fails and blocks merge +- ❌ Failure message clearly explains allowed formats \ No newline at end of file