Skip to content

Commit 75d32ff

Browse files
authored
πŸ‘·(ci) add commit-format job (#2)
* πŸ‘·(ci) add commit-format job * πŸ‘·(ci) separate squash check in post-merge workflow * πŸ’š(pr-on-main) fix commit-format error on merge commit * πŸ’„(ci) improve logs * πŸ‘·(ci) test workflow post-merge
1 parent 7249b36 commit 75d32ff

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
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, test-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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Pull Request Validation
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
types: [ opened, synchronize, reopened ]
7+
8+
jobs:
9+
commit-format:
10+
name: Check Commit Format
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
ref: ${{ github.head_ref }} # Checkout the PR branch without merging
18+
- name: Check single commit and format
19+
run: |
20+
# Get all PR commits
21+
BASE_SHA=$(git merge-base origin/main HEAD)
22+
COMMITS=$(git rev-list --reverse $BASE_SHA..HEAD)
23+
echo "Commits in this PR:"
24+
25+
# Commit message schema regex
26+
SCHEMA_REGEX="^(🎨|⚑️|πŸ”₯|πŸ›|πŸš‘οΈ|✨|πŸ“|πŸš€|πŸ’„|πŸŽ‰|βœ…|πŸ”’οΈ|πŸ”|πŸ”–|🚨|🚧|πŸ’š|⬇️|⬆️|πŸ“Œ|πŸ‘·|πŸ“ˆ|♻️|βž•|βž–|πŸ”§|πŸ”¨|🌐|✏️|πŸ’©|βͺ️|πŸ”€|πŸ“¦οΈ|πŸ‘½οΈ|🚚|πŸ“„|πŸ’₯|🍱|♿️|πŸ’‘|🍻|πŸ’¬|πŸ—ƒοΈ|πŸ”Š|πŸ”‡|πŸ‘₯|🚸|πŸ—οΈ|πŸ“±|🀑|πŸ₯š|πŸ™ˆ|πŸ“Έ|βš—οΈ|πŸ”οΈ|🏷️|🌱|🚩|πŸ₯…|πŸ’«|πŸ—‘οΈ|πŸ›‚|🩹|🧐|⚰️|πŸ§ͺ|πŸ‘”|🩺|🧱|πŸ§‘β€πŸ’»|πŸ’Έ|🧡|🦺|✈️)\\([a-z0-9:-]+\\) [a-z].{1,50}"
27+
28+
# Validate commit message schema
29+
INVALID_COMMITS=0
30+
for commit in $COMMITS; do
31+
MESSAGE=$(git log --format=%s -n 1 $commit)
32+
echo "$MESSAGE"
33+
34+
if ! echo "$MESSAGE" | grep -qE "$SCHEMA_REGEX"; then
35+
echo "❌ Invalid commit format: $MESSAGE"
36+
INVALID_COMMITS=$((INVALID_COMMITS + 1))
37+
fi
38+
done
39+
40+
if [ $INVALID_COMMITS -gt 0 ]; then
41+
echo "❌ $INVALID_COMMITS commit(s) with invalid format detected"
42+
echo "Required format: <emoji>(<scope>) <subject>"
43+
echo "Example: ✨(auth) add support for HTTP basic auth"
44+
exit 1
45+
fi
46+
47+
echo "βœ… All commits have valid format"

0 commit comments

Comments
Β (0)