diff --git a/src/main/kotlin/com/liftric/octopusdeploy/shell.kt b/src/main/kotlin/com/liftric/octopusdeploy/shell.kt index eb74c28..cadc9b3 100644 --- a/src/main/kotlin/com/liftric/octopusdeploy/shell.kt +++ b/src/main/kotlin/com/liftric/octopusdeploy/shell.kt @@ -1,15 +1,25 @@ package com.liftric.octopusdeploy +import org.slf4j.Logger import java.io.File -internal fun shell(cmd: String): ShellResult = File(".").shell(cmd) +internal fun shell(cmd: String, logger: Logger): ShellResult = File(".").shell(cmd, logger) -internal fun File.shell(cmd: String): ShellResult { - val process = Runtime.getRuntime().exec(arrayOf("sh", "-c", cmd), emptyArray(), this) +internal fun File.shell(cmd: String, logger: Logger): ShellResult { + val tmpDir = System.getProperty("java.io.tmpdir") + // DOTNET_BUNDLE_EXTRACT_BASE_DIR is a workaround for https://github.com/dotnet/runtime/issues/3846 + val cmdarray = arrayOf("sh", "-c", "DOTNET_BUNDLE_EXTRACT_BASE_DIR=$tmpDir $cmd") + val cmdDir = this + logger.debug("shell: cmdarray='${cmdarray.toList()}'") + logger.debug("shell: cmdDir='$cmdDir'") + logger.debug("shell: tmpDir='$tmpDir'") + val process = Runtime.getRuntime().exec(cmdarray, emptyArray(), cmdDir) val exitCode = process.waitFor() val inputText = process.inputStream.bufferedReader().readText().trim() val errorText = process.errorStream.bufferedReader().readText().trim() - return ShellResult(exitCode, inputText, errorText) + val result = ShellResult(exitCode, inputText, errorText) + logger.debug("shell: result=$result") + return result } -data class ShellResult(val exitCode: Int, val inputText: String, val errorText: String) \ No newline at end of file +data class ShellResult(val exitCode: Int, val inputText: String, val errorText: String) diff --git a/src/main/kotlin/com/liftric/octopusdeploy/task/CommitsSinceLastTagTask.kt b/src/main/kotlin/com/liftric/octopusdeploy/task/CommitsSinceLastTagTask.kt index d0d46dd..8a7c1fa 100644 --- a/src/main/kotlin/com/liftric/octopusdeploy/task/CommitsSinceLastTagTask.kt +++ b/src/main/kotlin/com/liftric/octopusdeploy/task/CommitsSinceLastTagTask.kt @@ -48,7 +48,8 @@ open class CommitsSinceLastTagTask : DefaultTask() { val firstCommitHash: String = firstCommitFile?.readText() ?: error("couldn't read firstCommitFile!") val (exitCode, inputText, errorText) = workingDir.shell( - "git log --pretty='format:%H#%s \\(%an\\)' ${previousTag ?: firstCommitHash}..HEAD" + "git log --pretty='format:%H#%s \\(%an\\)' ${previousTag ?: firstCommitHash}..HEAD", + logger ) if (exitCode == 0) { logger.info("previous tag: $inputText") diff --git a/src/main/kotlin/com/liftric/octopusdeploy/task/FirstCommitHashTask.kt b/src/main/kotlin/com/liftric/octopusdeploy/task/FirstCommitHashTask.kt index 1098aec..46e19c6 100644 --- a/src/main/kotlin/com/liftric/octopusdeploy/task/FirstCommitHashTask.kt +++ b/src/main/kotlin/com/liftric/octopusdeploy/task/FirstCommitHashTask.kt @@ -24,7 +24,10 @@ open class FirstCommitHashTask : DefaultTask() { @TaskAction fun execute() { - val (exitCode, inputText, errorText) = workingDir.shell("git log --pretty='format:%H' --reverse | head -1") + val (exitCode, inputText, errorText) = workingDir.shell( + "git log --pretty='format:%H' --reverse | head -1", + logger + ) if (exitCode == 0) { logger.info("first commit hash: $inputText") outputFile = File(outputDir, "firstCommitHash").apply { @@ -36,4 +39,4 @@ open class FirstCommitHashTask : DefaultTask() { throw IllegalStateException("git log exitCode: $exitCode") } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/liftric/octopusdeploy/task/PreviousTagTask.kt b/src/main/kotlin/com/liftric/octopusdeploy/task/PreviousTagTask.kt index f045cd0..66fbd03 100644 --- a/src/main/kotlin/com/liftric/octopusdeploy/task/PreviousTagTask.kt +++ b/src/main/kotlin/com/liftric/octopusdeploy/task/PreviousTagTask.kt @@ -2,7 +2,6 @@ package com.liftric.octopusdeploy.task import com.liftric.octopusdeploy.shell import org.gradle.api.DefaultTask -import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.* import java.io.File @@ -24,7 +23,7 @@ open class PreviousTagTask : DefaultTask() { @TaskAction fun execute() { - val (exitCode, inputText, errorText) = workingDir.shell("git describe --tags --abbrev=0 @^") + val (exitCode, inputText, errorText) = workingDir.shell("git describe --tags --abbrev=0 @^", logger) if (exitCode == 0) { logger.info("previous tag: $inputText") outputFile = File(outputDir, "previousTagName").apply { @@ -35,4 +34,4 @@ open class PreviousTagTask : DefaultTask() { logger.error(errorText) } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/liftric/octopusdeploy/task/PromoteReleaseTask.kt b/src/main/kotlin/com/liftric/octopusdeploy/task/PromoteReleaseTask.kt index c43e4d8..3fb66ae 100644 --- a/src/main/kotlin/com/liftric/octopusdeploy/task/PromoteReleaseTask.kt +++ b/src/main/kotlin/com/liftric/octopusdeploy/task/PromoteReleaseTask.kt @@ -75,7 +75,7 @@ open class PromoteReleaseTask : DefaultTask() { "--project=$projectNameValue", "--from=$fromValue", "--to=$toValue" - ).joinToString(" ").let { shell(it) } + ).joinToString(" ").let { shell(it, logger) } if (exitCode == 0) { println(inputText) println(errorText) diff --git a/src/main/kotlin/com/liftric/octopusdeploy/task/UploadBuildInformationTask.kt b/src/main/kotlin/com/liftric/octopusdeploy/task/UploadBuildInformationTask.kt index 01cea6d..ce3d358 100644 --- a/src/main/kotlin/com/liftric/octopusdeploy/task/UploadBuildInformationTask.kt +++ b/src/main/kotlin/com/liftric/octopusdeploy/task/UploadBuildInformationTask.kt @@ -50,16 +50,15 @@ open class UploadBuildInformationTask : DefaultTask() { packageName.get(), "--version=${version.get()}", overwriteMode?.let { "--overwrite-mode=$it" } - ).filterNotNull().joinToString(" ").let { shell(it) } + ).filterNotNull().joinToString(" ").let { shell(it, logger) } if (exitCode == 0) { println(inputText) println(errorText) } else { logger.error("octo build-information returned non-zero exitCode: $exitCode") - logger.error(inputText) + logger.error("inputStream='$inputText'") + logger.error("errorStream='$errorText'") throw IllegalStateException("octo build-information exitCode: $exitCode") } } - - } diff --git a/src/main/kotlin/com/liftric/octopusdeploy/task/UploadPackageTask.kt b/src/main/kotlin/com/liftric/octopusdeploy/task/UploadPackageTask.kt index 9da5289..eca28cc 100644 --- a/src/main/kotlin/com/liftric/octopusdeploy/task/UploadPackageTask.kt +++ b/src/main/kotlin/com/liftric/octopusdeploy/task/UploadPackageTask.kt @@ -10,7 +10,6 @@ import org.gradle.api.tasks.InputFile import org.gradle.api.tasks.Optional import org.gradle.api.tasks.TaskAction import org.gradle.kotlin.dsl.property -import java.io.File open class UploadPackageTask : DefaultTask() { init { @@ -73,7 +72,7 @@ open class UploadPackageTask : DefaultTask() { "--package", packageFile.get().asFile.absolutePath ?: error("couldn't find build-information.json"), overwriteMode?.let { "--overwrite-mode=$it" } - ).filterNotNull().joinToString(" ").let { shell(it) } + ).filterNotNull().joinToString(" ").let { shell(it, logger) } if (exitCode == 0) { println(inputText) println(errorText) diff --git a/src/test/kotlin/com/liftric/octopusdeploy/task/shared.kt b/src/test/kotlin/com/liftric/octopusdeploy/task/shared.kt index 49e23ce..4ad6942 100644 --- a/src/test/kotlin/com/liftric/octopusdeploy/task/shared.kt +++ b/src/test/kotlin/com/liftric/octopusdeploy/task/shared.kt @@ -1,10 +1,12 @@ package com.liftric.octopusdeploy.task import com.liftric.octopusdeploy.shell -import junit.framework.TestCase import junit.framework.TestCase.assertEquals +import org.slf4j.Logger +import org.slf4j.LoggerFactory import java.io.File +private val logger: Logger = LoggerFactory.getLogger("shared") fun File.setupGitRepo() { println("setupGitRepo=${this.absolutePath}") try { @@ -21,7 +23,7 @@ fun File.setupGitRepo() { } catch (e: Exception) { println(e.message) e.printStackTrace() - val (exitCode, inputText, errorText) = this.shell("ls -lah") + val (exitCode, inputText, errorText) = this.shell("ls -lah", logger) println("exitCode=$exitCode") println("inputText=$inputText") println("errorText=$errorText") @@ -31,7 +33,7 @@ fun File.setupGitRepo() { private fun File.verboseTestShell(cmd: String) { println("verboseTestShell=$cmd") - val (exitCode, inputText, errorText) = this.shell(cmd) + val (exitCode, inputText, errorText) = this.shell(cmd, logger) println("verboseTestShell exitCode=$exitCode") println("verboseTestShell inputText=$inputText") println("verboseTestShell errorText=$errorText")