-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* command : sh script/setup_lint.sh
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
echo "Running git pre-push hook" | ||
|
||
./gradlew detekt --daemon | ||
|
||
# $? = ".gradlew ktlintFormat --daemon"에 대한 return 값 | ||
STATUS=$? | ||
|
||
# 문제없이 끝났다면 exit 0, 아니면 1 | ||
[ $STATUS -ne 0 ] && exit 1 | ||
exit 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
|
||
# 현재 디렉터리 설정 | ||
LINTER_CURRENT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
PROJECT_ROOT="$LINTER_CURRENT_DIR/.." | ||
GRADLEW_SCRIPT_PATH="$LINTER_CURRENT_DIR/../gradlew" | ||
GIT_HOOK_DIR="$LINTER_CURRENT_DIR/../.git/hooks" | ||
DETEKT_TARGET_FILE="$GIT_HOOK_DIR/pre-push" | ||
KTLINT_TARGET_FILE="$GIT_HOOK_DIR/pre-commit" | ||
DETEKT_HOOK_SCRIPT="$LINTER_CURRENT_DIR/detekt_hook_script" | ||
|
||
# Git 저장소 확인 | ||
if ! git rev-parse --is-inside-work-tree &> /dev/null | ||
then | ||
echo "Error: Current directory is not a Git repository!" | ||
exit 1 | ||
fi | ||
|
||
# Gradle Wrapper 확인 | ||
if [[ ! -f "$GRADLEW_SCRIPT_PATH" ]] | ||
then | ||
echo "Error: Gradle Wrapper not found at $GRADLEW_SCRIPT_PATH" | ||
exit 1 | ||
fi | ||
|
||
# Git Hook 디렉터리 생성 | ||
if [[ ! -d "$GIT_HOOK_DIR" ]] | ||
then | ||
mkdir -p "$GIT_HOOK_DIR" | ||
fi | ||
|
||
# Detekt pre-push Hook 설치 확인 | ||
if [[ -f "$DETEKT_TARGET_FILE" ]] | ||
then | ||
echo "*************************************************" | ||
echo " Detekt integration failed " | ||
echo "*************************************************" | ||
echo "Reason: GIT pre-push hook is already installed!" | ||
exit 1 | ||
fi | ||
|
||
# KtLint Git Hooks pre-commit 추가 | ||
cd "$PROJECT_ROOT" || exit # 프로젝트 루트로 이동해야만 아래 명령어 작동 | ||
eval "$GRADLEW_SCRIPT_PATH addKtlintCheckGitPreCommitHook" | ||
chmod +x "$KTLINT_TARGET_FILE" | ||
|
||
# Detekt Hook 추가 | ||
if [[ ! -f "$DETEKT_HOOK_SCRIPT" ]] | ||
then | ||
echo "Error: Detekt hook script not found at $DETEKT_HOOK_SCRIPT" | ||
exit 1 | ||
fi | ||
|
||
cat "$DETEKT_HOOK_SCRIPT" > "$DETEKT_TARGET_FILE" | ||
chmod +x "$DETEKT_TARGET_FILE" | ||
|
||
echo "************************************************" | ||
echo " Linter installed " | ||
echo "************************************************" | ||
echo "Install path: $(ls "$GIT_HOOK_DIR")" |