diff --git a/.gitconfig b/.gitconfig new file mode 100644 index 00000000..e18ed830 --- /dev/null +++ b/.gitconfig @@ -0,0 +1,2 @@ +[core] + hooksPath = ".github/hooks" \ No newline at end of file diff --git a/.github/hooks/pre-commit b/.github/hooks/pre-commit new file mode 100755 index 00000000..3e0a1e59 --- /dev/null +++ b/.github/hooks/pre-commit @@ -0,0 +1,28 @@ +#!/bin/bash + +# Git 디렉토리 위치 +git_dir=$(git rev-parse --git-dir 2>/dev/null) || { echo "❌ Git 저장소만 지원한다."; exit 1; } + +# 방금 작성된 커밋 메시지 읽기 +commit_msg="$(< "$git_dir/COMMIT_EDITMSG")" + +# 메시지 패턴 정의 +regex="^(feat|fix|chore|docs|style|refactor|test|perf|ci|build|revert) *\([[:space:]]*#[[:space:]]*[0-9]+[[:space:]]*\) *: .+$" + +if [[ "$commit_msg" =~ $regex ]]; then + echo "✅ 커밋 메시지 형식이 올바릅니다." +else + echo "❌ 커밋 메시지 형식이 잘못되었습니다." + echo " 형식: 타입(#이슈번호) : 설명" + exit 1 +fi + +# 기존에 하던 Gradle 빌드 검증도 이어서 실행 +echo "Gradle 빌드 검증 시작..." +if ! ./gradlew clean build --no-daemon; then + echo "❌ 빌드 실패! 커밋 중단." + exit 1 +else + echo "✅ 빌드 성공! 커밋 계속." + exit 0 +fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 625ecc9e..00000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,14 +0,0 @@ -repos: - - repo: local - hooks: - - id: build-check - name: 빌드 검증 - entry: ./build-check.sh - language: script - pass_filenames: false - - - id: commit-msg-check - name: 커밋 메시지 포맷 검증 - entry: ./check-commit-message.sh - language: script - stages: [ commit-msg ] \ No newline at end of file diff --git a/build-check.sh b/build-check.sh deleted file mode 100755 index a08b49d2..00000000 --- a/build-check.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -cd "$(git rev-parse --show-toplevel)" || exit 1 - -echo "Gradle 빌드 검증 시작..." - -./gradlew clean build --no-daemon -BUILD_RESULT=$? - -if [ $BUILD_RESULT -ne 0 ]; then - echo "❌ 빌드 실패! 커밋이 중단됩니다." - exit 1 -else - echo "✅ 빌드 성공! 커밋 계속 진행합니다." - exit 0 -fi \ No newline at end of file diff --git a/check-commit-message.sh b/check-commit-message.sh deleted file mode 100755 index 5333a8af..00000000 --- a/check-commit-message.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -commit_msg=$(cat "$1") - -regex="^(feat|fix|chore|docs|style|refactor|test|perf|ci|build|revert) \([[:space:]]*#[[:space:]]*[0-9]+[[:space:]]*\) : .+$" - -if [[ "$commit_msg" =~ $regex ]]; then - echo "✅ 커밋 메시지 형식이 올바릅니다." - exit 0 -else - echo "❌ 커밋 메시지 형식이 잘못되었습니다." - exit 1 -fi