Skip to content

Commit 3d4c8fb

Browse files
authored
[#0] change rule of commit convention
1 parent 834b045 commit 3d4c8fb

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed
Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,53 @@
11
name: Check Commit Message Convention
22

3-
on:
4-
push:
5-
branches: [ '*' ]
6-
pull_request:
7-
branches: [ main ]
3+
on: pull_request
84

95
jobs:
106
check-commit-message:
117
runs-on: ubuntu-latest
128
steps:
13-
- name: Checkout code
9+
- name: Checkout code with full history
1410
uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0 # 전체 Git 히스토리를 가져옴
1513

16-
- 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
1718
run: |
18-
commit_message=$(git log --format=%s -n 1)
19-
echo "Last commit message: $commit_message"
20-
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
2125
22-
- name: Validate commit message
26+
- name: Validate commit messages
2327
run: |
24-
if [[ ! "$COMMIT_MESSAGE" =~ ^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?!?:\ .+ ]]; then
25-
echo "❌ Commit message does not follow the convention!"
26-
echo "Example: 'feat: add login API'"
28+
invalid_commits=0
29+
echo "🔍 Checking commit message convention..."
30+
31+
while IFS= read -r commit_message; do
32+
# "Merge"로 시작하는 메시지는 검사에서 제외
33+
if [[ "$commit_message" =~ ^Merge ]]; then
34+
echo "⚡ Skipping merge commit: $commit_message"
35+
continue
36+
fi
37+
38+
# Commit message validation (이슈 번호 기반 형식 검사)
39+
if [[ ! "$commit_message" =~ ^\[\#[0-9]+\]\ .+ ]]; then
40+
echo "❌ Invalid commit message format: $commit_message"
41+
invalid_commits=$((invalid_commits + 1))
42+
else
43+
echo "✅ Valid commit message: $commit_message"
44+
fi
45+
done <<< "$COMMIT_MESSAGES"
46+
47+
if [[ $invalid_commits -gt 0 ]]; then
48+
echo "🚨 Some commit messages do not follow the convention!"
49+
echo "Example: '[#1] 로그인 기능 함수 추가'"
2750
exit 1
2851
fi
29-
echo "✅ Commit message follows the convention!"
52+
53+
echo "🎉 All commit messages follow the convention!"

0 commit comments

Comments
 (0)