diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request-code.yml similarity index 99% rename from .github/workflows/pull-request.yml rename to .github/workflows/pull-request-code.yml index c05c622..de1b0e9 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request-code.yml @@ -1,4 +1,4 @@ -name: Pull Request Checks +name: PR Code Checks on: pull_request: diff --git a/.github/workflows/pull-request-format.yml b/.github/workflows/pull-request-format.yml new file mode 100644 index 0000000..37c24e0 --- /dev/null +++ b/.github/workflows/pull-request-format.yml @@ -0,0 +1,21 @@ +name: PR Format Checks +on: + pull_request: + types: + - opened + - edited + - synchronize + - reopened + +jobs: + conventional-commit: + name: Conventional Commit Title + runs-on: ubuntu-latest + # permissions: + # pull-requests: read + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Validate PR title + run: ./scripts/conventional-commit.sh "${{ github.event.pull_request.title }}" diff --git a/scripts/conventional-commit.sh b/scripts/conventional-commit.sh new file mode 100755 index 0000000..cca1a3e --- /dev/null +++ b/scripts/conventional-commit.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -euo pipefail + +TITLE="${1:-}" +if [[ -z "$TITLE" ]]; then + echo "::error::PR title is required" + exit 1 +fi + +TYPES_REGEX="build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test" + +# Conventional Commits: ()?(!)?: +RE="^(${TYPES_REGEX})(\([A-Za-z0-9._/-]+\))?(!)?: .+" + +if [[ ! "$TITLE" =~ $RE ]]; then + echo "::error::PR title must follow Conventional Commits. +Received: \"$TITLE\" +Expected: ()?: +Allowed types: ${TYPES_REGEX//|/, } +Examples: + - feat(api): add token exchange + - fix(auth)!: reject blank client_id + - chore: bump dependencies +" + exit 1 +fi + +echo "PR title OK: $TITLE"