1- name : CI
1+ name : Pull Request Validation
22
33on :
44 pull_request :
@@ -14,41 +14,34 @@ jobs:
1414 uses : actions/checkout@v4
1515 with :
1616 fetch-depth : 0
17- ref : ${{ github.head_ref }} # Checkout branch without merge
1817 - name : Check single commit and format
1918 run : |
20- # Check that there is only one commit in the PR
19+ # Get all PR commits
2120 BASE_SHA=$(git merge-base origin/main HEAD)
22- git log --oneline $BASE_SHA..HEAD
23-
24- COMMIT_COUNT=$(git rev-list --count $BASE_SHA..HEAD)
25- echo "Commit count: $COMMIT_COUNT"
26- if [ $COMMIT_COUNT -ne 1 ]; then
27- echo "❌ This PR contains $COMMIT_COUNT commits"
28- echo "Please squash your commits into a single commit before merging"
29- if [ $COMMIT_COUNT -gt 1 ]; then
30- echo "Use: git rebase -i HEAD~$COMMIT_COUNT"
31- fi
32- exit 1
33- fi
34-
35- echo "✅ Single commit detected"
36- echo "========================="
37-
38- # Get the commit message
39- MESSAGE=$(git log --format=%s -n 1 HEAD)
40- echo "Commit message: $MESSAGE"
21+ COMMITS=$(git rev-list --reverse $BASE_SHA..HEAD)
22+ echo "Commits in this PR:"
23+ echo "$COMMITS"
4124
4225 # Commit message schema regex
4326 SCHEMA_REGEX="^(🎨|⚡️|🔥|🐛|🚑️|✨|📝|🚀|💄|🎉|✅|🔒️|🔐|🔖|🚨|🚧|💚|⬇️|⬆️|📌|👷|📈|♻️|➕|➖|🔧|🔨|🌐|✏️|💩|⏪️|🔀|📦️|👽️|🚚|📄|💥|🍱|♿️|💡|🍻|💬|🗃️|🔊|🔇|👥|🚸|🏗️|📱|🤡|🥚|🙈|📸|⚗️|🔍️|🏷️|🌱|🚩|🥅|💫|🗑️|🛂|🩹|🧐|⚰️|🧪|👔|🩺|🧱|🧑💻|💸|🧵|🦺|✈️)\\([a-z0-9:-]+\\) [a-z].{1,50}"
4427
4528 # Validate commit message schema
46- if ! echo "$MESSAGE" | grep -qE "$SCHEMA_REGEX"; then
47- echo "❌ Invalid commit message!"
29+ INVALID_COMMITS=0
30+ for commit in $COMMITS; do
31+ MESSAGE=$(git log --format=%s -n 1 $commit)
32+ echo "Checking commit $commit: $MESSAGE"
33+
34+ if ! echo "$MESSAGE" | grep -qE "$SCHEMA_REGEX"; then
35+ INVALID_COMMITS=$((INVALID_COMMITS + 1))
36+ fi
37+ done
38+
39+ if [ $INVALID_COMMITS -gt 0 ]; then
40+ echo "❌ $INVALID_COMMITS commit(s) with invalid format detected"
4841 echo "Required format: <emoji>(<scope>) <subject>"
4942 echo "Example: ✨(auth) add support for HTTP basic auth"
5043 echo "Use 'bin/cz commit' to create commits with the correct format"
5144 exit 1
5245 fi
5346
54- echo "✅ Commit format is valid"
47+ echo "✅ All commits have valid format "
0 commit comments