|
6 | 6 | check-commit-message: |
7 | 7 | runs-on: ubuntu-latest |
8 | 8 | steps: |
9 | | - - name: Checkout code |
| 9 | + - name: Checkout code with full history |
10 | 10 | uses: actions/checkout@v4 |
| 11 | + with: |
| 12 | + fetch-depth: 0 # 전체 Git 히스토리를 가져옴 |
11 | 13 |
|
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 |
13 | 18 | 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 |
17 | 25 |
|
18 | | - - name: Validate commit message |
| 26 | + - name: Validate commit messages |
19 | 27 | 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!" |
22 | 48 | echo "Example: 'feat: add login API'" |
23 | 49 | exit 1 |
24 | 50 | fi |
25 | | - echo "✅ Commit message follows the convention!" |
| 51 | +
|
| 52 | + echo "🎉 All commit messages follow the convention!" |
0 commit comments