Skip to content

Commit

Permalink
chore: add PR title check workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Oct 1, 2024
1 parent 6891c04 commit f014b03
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/check-convential-commit-pr-title.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions scripts/generate-conventional-commit-regex.sh
Original file line number Diff line number Diff line change
@@ -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";

0 comments on commit f014b03

Please sign in to comment.