Skip to content

Commit 5eea364

Browse files
committed
ci: ✨ add commit message format validation
1 parent 30224e1 commit 5eea364

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,52 @@ on:
99
- master
1010

1111
jobs:
12+
commitlint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Validate commit message
21+
run: |
22+
# Get commit message(s) to validate
23+
if [ "${{ github.event_name }}" = "pull_request" ]; then
24+
COMMITS=$(git log --format=%s origin/${{ github.base_ref }}..HEAD)
25+
else
26+
COMMITS=$(git log -1 --format=%s)
27+
fi
28+
29+
# Conventional commit pattern: type(scope): emoji description
30+
# type is required, scope is optional, emoji after colon is optional
31+
PATTERN='^(feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert)(\([a-zA-Z0-9_-]+\))?: .+'
32+
33+
echo "Validating commit messages..."
34+
FAILED=0
35+
while IFS= read -r MSG; do
36+
if [ -n "$MSG" ]; then
37+
if echo "$MSG" | grep -qE "$PATTERN"; then
38+
echo "✅ $MSG"
39+
else
40+
echo "❌ $MSG"
41+
echo " Expected format: type(scope): description"
42+
echo " Example: feat(auth): ✨ add login feature"
43+
FAILED=1
44+
fi
45+
fi
46+
done <<< "$COMMITS"
47+
48+
if [ $FAILED -eq 1 ]; then
49+
echo ""
50+
echo "Commit message validation failed!"
51+
echo "Please follow Conventional Commits: https://www.conventionalcommits.org/"
52+
exit 1
53+
fi
54+
1255
ci:
1356
runs-on: ubuntu-latest
57+
needs: commitlint
1458

1559
steps:
1660
- name: Checkout code

0 commit comments

Comments
 (0)