From 45742a9e998a5479d1c833c01db73794651f4ffd Mon Sep 17 00:00:00 2001 From: khope Date: Fri, 7 Nov 2025 14:42:14 +0900 Subject: [PATCH 1/4] find build module --- build.gradle.kts | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 4020069..d34db7c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,6 @@ +import org.gradle.internal.impldep.org.eclipse.jgit.revwalk.filter.RevFilter.MERGE_BASE +import java.io.ByteArrayOutputStream + plugins { kotlin("jvm") version "1.9.25" apply false kotlin("plugin.spring") version "1.9.25" apply false @@ -24,3 +27,67 @@ subprojects { useJUnitPlatform() } } + +tasks.register("findBuildModule") { + group = "build analysis" + description = "Detect changed modules among allowedBuildModules only" + + val allowedBuildModules = listOf( + "ai", + "exporter", + "cli" + ) + + doLast { + val branchNameOut = ByteArrayOutputStream() + exec { + commandLine("git", "rev-parse", "--abbrev-ref", "HEAD") + standardOutput = branchNameOut + } + val currentBranch = branchNameOut.toString().trim() + println("πŸ” ν˜„μž¬ 브랜치: $currentBranch") + + val output = ByteArrayOutputStream() + exec { + commandLine("bash", "-c", """ + git fetch origin master; + MERGE_BASE=$(git merge-base HEAD origin/master); + (git diff --name-only $MERGE_BASE HEAD || true); + (git diff --cached --name-only || true); + (git diff --name-only || true) + """.trimIndent()) + standardOutput = output + } + + val changedFiles = output.toString().trim().lines().filter { it.isNotBlank() } + if (changedFiles.isEmpty()) { + println("βœ… λ³€κ²½λœ 파일이 μ—†μŠ΅λ‹ˆλ‹€.") + return@doLast + } + + val changedModules = mutableSetOf() + + rootProject.subprojects.forEach { project -> + val projectPath = project.projectDir.toPath().toAbsolutePath().normalize().toString() + val rootPath = rootProject.projectDir.toPath().toAbsolutePath().normalize().toString() + val relPath = projectPath.replace("$rootPath${File.separator}", "").replace('\\', '/') + + changedFiles.forEach { file -> + if (file.startsWith("$relPath/") && allowedBuildModules.contains(project.name)) { + changedModules += project.name + } + } + } + + println("") + println("🟨 κ°μ§€λœ λΉŒλ“œ λŒ€μƒ λͺ¨λ“ˆ (allowedBuildModules ν•œμ •)") + if (changedModules.isEmpty()) { + println(" (μ—†μŒ)") + } else { + changedModules.forEach { println(" - $it") } + } + + println("") + println("[μ°Έκ³ ] master와 diff κΈ°μ€€μœΌλ‘œ κ°μ§€λ˜λ―€λ‘œ, λΈŒλžœμΉ˜κ°€ 였래되면 κ²°κ³Ό 정확도가 λ–¨μ–΄μ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€.") + } +} From 0d43d6947ca3b819d9d8e5b4dbe541b994455ce8 Mon Sep 17 00:00:00 2001 From: khope Date: Fri, 7 Nov 2025 14:50:22 +0900 Subject: [PATCH 2/4] find build module --- build.gradle.kts | 115 ++++++++++++------ .../scheduler/MetricScheduler.kt | 2 + 2 files changed, 79 insertions(+), 38 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d34db7c..5d7e2bd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,7 @@ -import org.gradle.internal.impldep.org.eclipse.jgit.revwalk.filter.RevFilter.MERGE_BASE +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.TaskAction +import org.gradle.process.ExecOperations +import javax.inject.Inject import java.io.ByteArrayOutputStream plugins { @@ -28,66 +31,102 @@ subprojects { } } -tasks.register("findBuildModule") { - group = "build analysis" - description = "Detect changed modules among allowedBuildModules only" - - val allowedBuildModules = listOf( - "ai", - "exporter", - "cli" - ) - - doLast { - val branchNameOut = ByteArrayOutputStream() - exec { - commandLine("git", "rev-parse", "--abbrev-ref", "HEAD") - standardOutput = branchNameOut + + +abstract class FindBuildModuleTask @Inject constructor( + private val execOps: ExecOperations +) : DefaultTask() { + + @TaskAction + fun run() { + val allowedBuildModules = listOf( + "exporter", + "ai", + "cli" + ) + + fun execAndCapture(vararg cmd: String): String { + val output = ByteArrayOutputStream() + execOps.exec { + commandLine(*cmd) + standardOutput = output + errorOutput = ByteArrayOutputStream() + isIgnoreExitValue = true + } + return output.toString().trim() } - val currentBranch = branchNameOut.toString().trim() + + val currentBranch = execAndCapture("git", "rev-parse", "--abbrev-ref", "HEAD") println("πŸ” ν˜„μž¬ 브랜치: $currentBranch") - val output = ByteArrayOutputStream() - exec { - commandLine("bash", "-c", """ - git fetch origin master; - MERGE_BASE=$(git merge-base HEAD origin/master); - (git diff --name-only $MERGE_BASE HEAD || true); - (git diff --cached --name-only || true); - (git diff --name-only || true) - """.trimIndent()) - standardOutput = output + execOps.exec { + commandLine("git", "fetch", "origin", "master") + isIgnoreExitValue = true + } + + val mergeBaseOutput = ByteArrayOutputStream() + execOps.exec { + commandLine("git", "merge-base", "HEAD", "origin/master") + standardOutput = mergeBaseOutput + isIgnoreExitValue = true } + val mergeBase = mergeBaseOutput.toString().trim() + + if (mergeBase.isBlank()) { + println("⚠️ merge-baseλ₯Ό 찾을 수 μ—†μŠ΅λ‹ˆλ‹€. 브랜치 동기화 μƒνƒœλ₯Ό ν™•μΈν•˜μ„Έμš”.") + return + } + + val diffOutput = ByteArrayOutputStream() + execOps.exec { + commandLine( + "bash", "-c", """ + git diff --name-only $mergeBase..HEAD + git diff --cached --name-only + git diff --name-only + """.trimIndent() + ) + standardOutput = diffOutput + isIgnoreExitValue = true + } + + val changedFiles = diffOutput.toString().trim().lines().filter { it.isNotBlank() } - val changedFiles = output.toString().trim().lines().filter { it.isNotBlank() } if (changedFiles.isEmpty()) { println("βœ… λ³€κ²½λœ 파일이 μ—†μŠ΅λ‹ˆλ‹€.") - return@doLast + return } val changedModules = mutableSetOf() + val rootPath = project.rootDir.absolutePath - rootProject.subprojects.forEach { project -> - val projectPath = project.projectDir.toPath().toAbsolutePath().normalize().toString() - val rootPath = rootProject.projectDir.toPath().toAbsolutePath().normalize().toString() - val relPath = projectPath.replace("$rootPath${File.separator}", "").replace('\\', '/') + project.rootProject.subprojects.forEach { sub -> + val relPath = sub.projectDir.absolutePath + .replace(rootPath + File.separator, "") + .replace("\\", "/") changedFiles.forEach { file -> - if (file.startsWith("$relPath/") && allowedBuildModules.contains(project.name)) { - changedModules += project.name + if (file.startsWith("$relPath/") && allowedBuildModules.contains(sub.name)) { + changedModules += sub.name } } } - println("") - println("🟨 κ°μ§€λœ λΉŒλ“œ λŒ€μƒ λͺ¨λ“ˆ (allowedBuildModules ν•œμ •)") + println() + println("🟨 κ°μ§€λœ λΉŒλ“œ λŒ€μƒ λͺ¨λ“ˆ (exporter, ai, cli ν•œμ •)") if (changedModules.isEmpty()) { println(" (μ—†μŒ)") } else { changedModules.forEach { println(" - $it") } } - println("") + println() println("[μ°Έκ³ ] master와 diff κΈ°μ€€μœΌλ‘œ κ°μ§€λ˜λ―€λ‘œ, λΈŒλžœμΉ˜κ°€ 였래되면 κ²°κ³Ό 정확도가 λ–¨μ–΄μ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€.") } } + +tasks.register("findBuildModule") { + group = "build analysis" + description = "Detect changed modules among exporter, ai, cli only" +} + diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt b/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt index b8feb81..6e7f5e7 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt @@ -18,8 +18,10 @@ class JvmMonitoringScheduler( private val classLoadingRepository: ClassLoadingInfoRepository, private val applicationRepository: ApplicationRepository, ) { + // Test @Scheduled(fixedRate = 1000) fun collectAndSaveJvmMetrics() { + println("Hello World") val memoryEntity = JvmMonitoringMapper.toEntity(jvmExporter.getMemoryInfo(), TEST) memoryRepository.save(memoryEntity) From c65b8302c30eaae00474e981b02b32fe78668e30 Mon Sep 17 00:00:00 2001 From: rlaope Date: Fri, 7 Nov 2025 14:52:28 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD=EC=82=AC=ED=95=AD=20?= =?UTF-8?q?=EB=84=A3=EC=96=B4=EB=86=A8=EB=8D=98=EA=B1=B0=20=EB=A1=A4?= =?UTF-8?q?=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt b/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt index 6e7f5e7..b8feb81 100644 --- a/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt +++ b/exporter/src/main/kotlin/lab/monilabexporterex/scheduler/MetricScheduler.kt @@ -18,10 +18,8 @@ class JvmMonitoringScheduler( private val classLoadingRepository: ClassLoadingInfoRepository, private val applicationRepository: ApplicationRepository, ) { - // Test @Scheduled(fixedRate = 1000) fun collectAndSaveJvmMetrics() { - println("Hello World") val memoryEntity = JvmMonitoringMapper.toEntity(jvmExporter.getMemoryInfo(), TEST) memoryRepository.save(memoryEntity) From a4e6fb1f4108020ae1a0aa93114c1d17483ada56 Mon Sep 17 00:00:00 2001 From: rlaope Date: Fri, 7 Nov 2025 14:53:22 +0900 Subject: [PATCH 4/4] lint --- build.gradle.kts | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5d7e2bd..3367772 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,8 +31,6 @@ subprojects { } } - - abstract class FindBuildModuleTask @Inject constructor( private val execOps: ExecOperations ) : DefaultTask() {