-
Notifications
You must be signed in to change notification settings - Fork 2
[Feature] pre-push hook을 통한 변경 모듈 대상 lint 및 정적분석 실행 #1330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
52a1c9e
feat: add pre-push hook to run lint only on affected modules
skdud0629 7300356
fix: run spotlessCheck at root level instead of per module
skdud0629 01dc050
fix: branch name
skdud0629 1c4145e
refactor: dynamically parse modules from settings.gradle instead of h…
skdud0629 f2ce02d
Del: wrong alphabet
skdud0629 6423eea
fix: reorder lint tasks to run spotlessCheck before ktlintCheck
skdud0629 ecb8693
Add: newline
skdud0629 21c6ee3
fix: permission
skdud0629 4cb955b
fix: use env bash shebang to support Homebrew bash 4.0+
skdud0629 91a40bc
Update .githooks/pre-push
skdud0629 e87f4d5
Update .githooks/pre-push
skdud0629 e41514b
Fix: change test order
skdud0629 77d16c0
Update .githooks/pre-push
skdud0629 068d4fb
Update .githooks/pre-push
skdud0629 3165121
Add automatic Git hooks configuration via preBuild task
skdud0629 64cd043
fix pre-push hook to handle modules without detekt task
skdud0629 10ee17a
Add: jvm version
skdud0629 182cd9f
Update .githooks/pre-push
skdud0629 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,91 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -e | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if ((BASH_VERSINFO[0] < 4)); then | ||
| echo "[pre-push] Error: bash 4.0+ is required. Install with: brew install bash" | ||
| exit 1 | ||
| fi | ||
|
|
||
| MAIN_BRANCH="origin/develop" | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| MERGE_BASE=$(git merge-base HEAD "$MAIN_BRANCH" 2>/dev/null || git merge-base HEAD develop 2>/dev/null || true) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Major] pre-push 훅의 stdin 입력을 무시하고 있습니다 Git pre-push 훅은 stdin으로 실제 push되는 ref 정보를 전달합니다: 현재 스크립트는 이 입력을 전혀 읽지 않고 항상
stdin을 읽어 실제 push 범위를 기반으로 변경 파일을 탐지하는 방식을 권장합니다: while read local_ref local_sha remote_ref remote_sha; do
if [ "$local_sha" = "0000000000000000000000000000000000000000" ]; then
continue # branch deletion, skip
fi
if [ "$remote_sha" = "0000000000000000000000000000000000000000" ]; then
# new branch being pushed
RANGE="$local_sha"
else
RANGE="$remote_sha..$local_sha"
fi
CHANGED_FILES=$(git diff --name-only "$RANGE")
done |
||
|
|
||
| if [ -z "$MERGE_BASE" ]; then | ||
| echo "[pre-push] Could not determine merge base. Running full check..." | ||
| ./gradlew spotlessCheck ktlintCheck detekt | ||
| exit 0 | ||
| fi | ||
|
|
||
| CHANGED_FILES=$(git diff --name-only "$MERGE_BASE" HEAD) | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if [ -z "$CHANGED_FILES" ]; then | ||
| echo "[pre-push] No changed files. Skipping checks." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "[pre-push] Changed files:" | ||
| echo "$CHANGED_FILES" | sed 's/^/ /' | ||
|
|
||
| # Parse modules from settings.gradle dynamically | ||
| declare -A MODULE_PATHS # module -> dir path | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| while IFS= read -r line; do | ||
| for token in $line; do | ||
| token="${token//\'/}" | ||
| token="${token//,/}" | ||
| if [[ "$token" == :* ]]; then | ||
| dir="${token//://}" | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dir="${dir#/}" | ||
| MODULE_PATHS["$token"]="$dir" | ||
| fi | ||
| done | ||
| done < <(grep "^include" settings.gradle) | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Map changed files to affected modules | ||
| declare -A MODULES | ||
| RUN_ALL=false | ||
|
|
||
| while IFS= read -r file; do | ||
| case "$file" in | ||
| build-logic/*|build.gradle|build.gradle.kts|gradle.properties|settings.gradle|settings.gradle.kts|gradle/libs.versions.toml) | ||
| RUN_ALL=true | ||
| break | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ;; | ||
| esac | ||
| matched_module="" | ||
| matched_len=0 | ||
| for module in "${!MODULE_PATHS[@]}"; do | ||
| dir="${MODULE_PATHS[$module]}" | ||
| if [[ "$file" == "$dir/"* ]]; then | ||
| if (( ${#dir} > matched_len )); then | ||
| matched_module="$module" | ||
| matched_len=${#dir} | ||
| fi | ||
| fi | ||
| done | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [[ -n "$matched_module" ]]; then | ||
| MODULES["$matched_module"]=1 | ||
| fi | ||
| done <<< "$CHANGED_FILES" | ||
|
|
||
| if [ "$RUN_ALL" = true ]; then | ||
| echo "[pre-push] Build-level changes detected. Running full check..." | ||
| ./gradlew spotlessCheck ktlintCheck detekt | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ ${#MODULES[@]} -eq 0 ]; then | ||
| echo "[pre-push] No affected modules detected. Skipping checks." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "[pre-push] Affected modules: ${!MODULES[*]}" | ||
|
|
||
| TASKS=("spotlessCheck") | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| for module in "${!MODULES[@]}"; do | ||
| TASKS+=("${module}:ktlintCheck") | ||
| if ./gradlew "${module}:tasks" --quiet 2>/dev/null | grep -q "^detekt "; then | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| TASKS+=("${module}:detekt") | ||
| fi | ||
| done | ||
| echo "[pre-push] Running: ./gradlew ${TASKS[*]}" | ||
| ./gradlew --continue "${TASKS[@]}" | ||
skdud0629 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.