diff --git a/.github/workflows/check-convential-commit-pr-title.yml b/.github/workflows/check-convential-commit-pr-title.yml new file mode 100644 index 00000000000..b3a656dab53 --- /dev/null +++ b/.github/workflows/check-convential-commit-pr-title.yml @@ -0,0 +1,28 @@ +name: Check Conventional Commit PR Title + +on: + pull_request: + types: [opened, edited, reopened] + +jobs: + check-pr-title: + runs-on: ubuntu-latest + env: + PR_TITLE: ${{ github.event.pull_request.title }} + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + path: amplify-js + - name: Generate Regex and Check PR title + working-directory: ./amplify-js + run: | + regex=$(./scripts/generate-conventional-commit-regex.sh) + if [[ "$PR_TITLE" =~ $regex ]]; then + echo "✅ PR title '$PR_TITLE' is valid" + exit 0 + else + echo "❌ PR title '$PR_TITLE' is invalid" + echo "It should match the pattern: $regex" + exit 1 + fi diff --git a/scripts/generate-conventional-commit-regex.sh b/scripts/generate-conventional-commit-regex.sh new file mode 100755 index 00000000000..1a5b34362f6 --- /dev/null +++ b/scripts/generate-conventional-commit-regex.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Get the list of directory names under ./packages +scopes=$(ls -d ./packages/*/ 2>/dev/null | xargs -n 1 basename | tr '\n' '|' | sed 's/|$//') + +# Generate the regular expression +regex="^(feat|fix|docs|style|refactor|perf|test|chore|revert|release)(\(($scopes|required)\))?: .+$" + +# Output the generated regex +echo "$regex";