Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.sonarsource.cloudnative.gradle.GoBuild
import org.sonarsource.cloudnative.gradle.allGoSourcesAndMakeScripts
import org.sonarsource.cloudnative.gradle.callMake
import org.sonarsource.cloudnative.gradle.crossCompileEnv
import org.sonarsource.cloudnative.gradle.findExecutable
import org.sonarsource.cloudnative.gradle.getArchitecture
import org.sonarsource.cloudnative.gradle.getPlatform
import org.sonarsource.cloudnative.gradle.goLangCiLintVersion
Expand Down Expand Up @@ -50,6 +51,8 @@ goBuildExtension.dockerCommands.convention(
)

if (isCi()) {
val goLangCiLintExecutable = findExecutable("golangci-lint")

val cleanGoCode by tasks.registering(Exec::class) {
description = "Clean all compiled version of the go code."
group = "build"
Expand Down Expand Up @@ -92,7 +95,7 @@ if (isCi()) {
outputs.cacheIf { true }

commandLine(
"golangci-lint",
goLangCiLintExecutable,
"run",
// Don't limit the number of issues in the report
"--max-issues-per-linter=0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ import org.sonarsource.cloudnative.gradle.GO_LICENSES_OUTPUT_DIR
import org.sonarsource.cloudnative.gradle.GoBuild
import org.sonarsource.cloudnative.gradle.allGoSourcesAndMakeScripts
import org.sonarsource.cloudnative.gradle.crossCompileEnv
import org.sonarsource.cloudnative.gradle.findExecutable
import org.sonarsource.cloudnative.gradle.goLangCiLintVersion
import org.sonarsource.cloudnative.gradle.goVersion
import org.sonarsource.cloudnative.gradle.isCi

val dockerExecutable = findExecutable("docker")

val goBuildExtension = extensions.findByType<GoBuild>() ?: extensions.create<GoBuild>("goBuild")

val buildDockerImage by tasks.registering(Exec::class) {
Expand All @@ -49,7 +52,7 @@ val buildDockerImage by tasks.registering(Exec::class) {
val noTrafficInspection = "false" == System.getProperty("trafficInspection")

val arguments = buildList {
add("docker")
add(dockerExecutable)
add("buildx")
add("build")
add("--file")
Expand Down Expand Up @@ -102,7 +105,7 @@ val dockerTasks = goBuildExtension.dockerCommands.map { tasksToCommands ->

val workDir = goBuildExtension.dockerWorkDir.get()
commandLine(
"docker",
dockerExecutable,
"run",
"--rm",
"--network=host",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,29 @@ import org.gradle.internal.os.OperatingSystem

fun isCi() = System.getenv("CI")?.equals("true") == true

/**
* Resolves the absolute path of an executable by searching the PATH environment variable.
* This works around a JDK 21 issue where process creation may not properly resolve executables from PATH.
* Falls back to the bare executable name if not found (letting the OS handle resolution).
*/
fun findExecutable(name: String): String {
val pathSeparator = File.pathSeparator
val executableExtensions = if (OperatingSystem.current().isWindows) listOf(".exe", ".cmd", ".bat", "") else listOf("")
val pathDirs = System.getenv("PATH")
?.split(pathSeparator)
?.filter { it.isNotBlank() }
?: return name
for (dir in pathDirs) {
for (ext in executableExtensions) {
val candidate = File(dir, "$name$ext")
if (candidate.isFile && candidate.canExecute()) {
return candidate.absolutePath
}
}
}
return name
}

fun Project.signingCondition(): Boolean {
val branch = System.getenv("GITHUB_REF_NAME") ?: System.getenv("CIRRUS_BRANCH") ?: ""
return (branch == "master" || branch.matches("branch-.+".toRegex())) &&
Expand Down Expand Up @@ -100,7 +123,7 @@ fun checkJarEntriesPathUniqueness(file: File) {

fun Project.commitHashProvider(ref: String = "HEAD") =
providers.exec {
commandLine("git", "rev-parse", ref)
commandLine(findExecutable("git"), "rev-parse", ref)
}.standardOutput.asText

fun getPlatform(): String {
Expand Down
Loading