Skip to content

Commit 567d595

Browse files
committed
👷(ci) separate squash check in post-merge workflow
1 parent e73e05c commit 567d595

File tree

2 files changed

+65
-25
lines changed

2 files changed

+65
-25
lines changed

.github/workflows/post-merge.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Post-merge validation
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
squash-check:
9+
name: Check Commits Are Squashed
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Check squash merge
18+
run: |
19+
# Check that only one commit was added to main
20+
PREVIOUS_COMMIT=$(git rev-parse HEAD~1)
21+
COMMITS_ADDED=$(git rev-list --count $PREVIOUS_COMMIT..HEAD)
22+
23+
echo "Previous commit: $(git rev-parse --short $PREVIOUS_COMMIT)"
24+
echo "Current commit: $(git rev-parse --short HEAD)"
25+
echo "Commits added: $COMMITS_ADDED"
26+
27+
if [ $COMMITS_ADDED -ne 1 ]; then
28+
echo "❌ Merge was not squashed! $COMMITS_ADDED commits were added to main"
29+
echo "Please use 'Squash and merge' when merging PRs"
30+
exit 1
31+
fi
32+
33+
echo "✅ Merge was properly squashed (1 commit added)"
34+
35+
# Validate the commit message format
36+
MESSAGE=$(git log --format=%s -n 1 HEAD)
37+
echo "Merged commit message: $MESSAGE"
38+
39+
SCHEMA_REGEX="^(🎨|⚡️|🔥|🐛|🚑️|✨|📝|🚀|💄|🎉|✅|🔒️|🔐|🔖|🚨|🚧|💚|⬇️|⬆️|📌|👷|📈|♻️|➕|➖|🔧|🔨|🌐|✏️|💩|⏪️|🔀|📦️|👽️|🚚|📄|💥|🍱|♿️|💡|🍻|💬|🗃️|🔊|🔇|👥|🚸|🏗️|📱|🤡|🥚|🙈|📸|⚗️|🔍️|🏷️|🌱|🚩|🥅|💫|🗑️|🛂|🩹|🧐|⚰️|🧪|👔|🩺|🧱|🧑‍💻|💸|🧵|🦺|✈️)\\([a-z0-9:-]+\\) [a-z].{1,50}"
40+
41+
if ! echo "$MESSAGE" | grep -qE "$SCHEMA_REGEX"; then
42+
echo "❌ Merged commit has invalid format: $MESSAGE"
43+
echo "Required format: <emoji>(<scope>) <subject>"
44+
exit 1
45+
fi
46+
47+
echo "✅ Merged commit format is valid"
Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI
1+
name: Pull Request Validation
22

33
on:
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

Comments
 (0)