Skip to content

Commit 100bec8

Browse files
authored
[#0] fix and enhance check-commit-convention.yml to work well
1 parent 48b03bb commit 100bec8

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

.github/workflows/check-commit-convention.yml

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,47 @@ jobs:
66
check-commit-message:
77
runs-on: ubuntu-latest
88
steps:
9-
- name: Checkout code
9+
- name: Checkout code with full history
1010
uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0 # 전체 Git 히스토리를 가져옴
1113

12-
- name: Get last commit message
14+
- name: Get base branch
15+
run: echo "BASE_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV
16+
17+
- name: Get all new commit messages in PR
1318
run: |
14-
commit_message=$(git log --format=%s -n 1)
15-
echo "Last commit message: $commit_message"
16-
echo "COMMIT_MESSAGE=$commit_message" >> $GITHUB_ENV
19+
commit_messages=$(git log --format=%s origin/$BASE_BRANCH..HEAD)
20+
echo "Commit Messages in PR:"
21+
echo "$commit_messages"
22+
echo "COMMIT_MESSAGES<<EOF" >> $GITHUB_ENV
23+
echo "$commit_messages" >> $GITHUB_ENV
24+
echo "EOF" >> $GITHUB_ENV
1725
18-
- name: Validate commit message
26+
- name: Validate commit messages
1927
run: |
20-
if [[ ! "$COMMIT_MESSAGE" =~ ^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?!?:\ .+ ]]; then
21-
echo "❌ Commit message does not follow the convention!"
28+
invalid_commits=0
29+
echo "🔍 Checking commit message convention..."
30+
while IFS= read -r commit_message; do
31+
# "Merge"로 시작하는 메시지는 검사에서 제외
32+
if [[ "$commit_message" =~ ^Merge ]]; then
33+
echo "⚡ Skipping merge commit: $commit_message"
34+
continue
35+
fi
36+
37+
# Commit message validation
38+
if [[ ! "$commit_message" =~ ^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?!?:\ .+ ]]; then
39+
echo "❌ Invalid commit message: $commit_message"
40+
invalid_commits=$((invalid_commits + 1))
41+
else
42+
echo "✅ Valid commit message: $commit_message"
43+
fi
44+
done <<< "$COMMIT_MESSAGES"
45+
46+
if [[ $invalid_commits -gt 0 ]]; then
47+
echo "🚨 Some commit messages do not follow the convention!"
2248
echo "Example: 'feat: add login API'"
2349
exit 1
2450
fi
25-
echo "✅ Commit message follows the convention!"
51+
52+
echo "🎉 All commit messages follow the convention!"

0 commit comments

Comments
 (0)