[자동차 경주] 송채원 미션 제출합니다. #27
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Check Commit Message Convention | |
on: pull_request | |
jobs: | |
check-commit-message: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code with full history | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # 전체 Git 히스토리를 가져옴 | |
- name: Get base branch | |
run: echo "BASE_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV | |
- name: Get all new commit messages in PR | |
run: | | |
commit_messages=$(git log --format=%s origin/$BASE_BRANCH..HEAD) | |
echo "Commit Messages in PR:" | |
echo "$commit_messages" | |
echo "COMMIT_MESSAGES<<EOF" >> $GITHUB_ENV | |
echo "$commit_messages" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Validate commit messages | |
run: | | |
invalid_commits=0 | |
echo "🔍 Checking commit message convention..." | |
while IFS= read -r commit_message; do | |
# "Merge"로 시작하는 메시지는 검사에서 제외 | |
if [[ "$commit_message" =~ ^Merge ]]; then | |
echo "⚡ Skipping merge commit: $commit_message" | |
continue | |
fi | |
# Commit message validation | |
if [[ ! "$commit_message" =~ ^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?!?:\ .+ ]]; then | |
echo "❌ Invalid commit message: $commit_message" | |
invalid_commits=$((invalid_commits + 1)) | |
else | |
echo "✅ Valid commit message: $commit_message" | |
fi | |
done <<< "$COMMIT_MESSAGES" | |
if [[ $invalid_commits -gt 0 ]]; then | |
echo "🚨 Some commit messages do not follow the convention!" | |
echo "Example: 'feat: add login API'" | |
exit 1 | |
fi | |
echo "🎉 All commit messages follow the convention!" |