Skip to content
Closed
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
32 changes: 32 additions & 0 deletions .github/workflows/pr-title-validation.yml
Original file line number Diff line number Diff line change
@@ -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)
...
82 changes: 82 additions & 0 deletions docs/31.pr-title-validation.md
Original file line number Diff line number Diff line change
@@ -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