From 18bdaaeaa16ca681f1599cf95ffa1233ecf00c52 Mon Sep 17 00:00:00 2001 From: Peter Gafert Date: Fri, 29 Oct 2021 00:23:39 +0700 Subject: [PATCH] add short sleep time after executing commands I could not find out why this happens, but for example if we call `git checkout -b` immediately followed by `git rev-parse` from Gradle the output will be empty. I tried to reproduce it locally and with plain Git but couldn't. It only happens during the release job when it runs as GitHub action, so it is quite hard to debug. By my understanding the process should be finished if `waitFor()` returns (and the exit code is even 0), but somehow this does not work reliably. So for now I decided to go the quick and dirty way and simply add a short sleep time after executing shell commands. Signed-off-by: Peter Gafert --- build-steps/release/process-utils.gradle | 14 ++++++++++++++ build-steps/release/publish.gradle | 19 +++---------------- build-steps/release/vcs-utils.gradle | 4 +++- 3 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 build-steps/release/process-utils.gradle diff --git a/build-steps/release/process-utils.gradle b/build-steps/release/process-utils.gradle new file mode 100644 index 0000000000..79b4819cfa --- /dev/null +++ b/build-steps/release/process-utils.gradle @@ -0,0 +1,14 @@ +ext.executeCommand = { List command -> + new StringBuilder().with { output -> + def error = new StringBuilder() + def exitCode = command.execute() + .with { + it.consumeProcessOutputStream(output) + it.consumeProcessErrorStream(error) + it + }.waitFor() + Thread.sleep(100) // For some reason a call right after `waitFor` might fail, so we wait a little bit :-( + assert exitCode == 0: "Command '$command' failed with exit code $exitCode: $error" + output.toString().trim() + } +} \ No newline at end of file diff --git a/build-steps/release/publish.gradle b/build-steps/release/publish.gradle index dc3716123e..421e2e9db0 100644 --- a/build-steps/release/publish.gradle +++ b/build-steps/release/publish.gradle @@ -1,6 +1,7 @@ ext.isReleaseVersion = !project.version.endsWith("-SNAPSHOT") apply plugin: "io.github.gradle-nexus.publish-plugin" +apply from: scriptRelativePath(this, 'process-utils.gradle') nexusPublishing { packageGroup = 'com.tngtech' @@ -124,27 +125,13 @@ def updateVersion = { Closure calculateNewVersion -> rootProject.allprojects { it.version = newVersion } } -def executeCommand = { String command -> - new StringBuilder().with { output -> - def error = new StringBuilder() - def exitCode = command.split(' ').execute() - .with { - it.consumeProcessOutputStream(output) - it.consumeProcessErrorStream(error) - it - }.waitFor() - assert exitCode == 0: "Command '$command' failed with exit code $exitCode: $error" - output.toString().trim() - } -} - task prepareRelease() { doFirst { String releaseVersion = withCurrentVersion { int oldMajor, int oldMinor, int oldPatch, String oldSuffix -> "$oldMajor.$oldMinor.$oldPatch" } def releaseBranch = "release-$releaseVersion" - executeCommand("git checkout -b $releaseBranch") - String currentBranch = executeCommand('git rev-parse --abbrev-ref HEAD') + executeCommand(['git', 'checkout', '-b', "$releaseBranch"]) + String currentBranch = executeCommand(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) assert currentBranch == releaseBranch: "Mismatch: Should be on branch $releaseBranch but current branch is $currentBranch" updateVersion { major, minor, patch, suffix -> releaseVersion } diff --git a/build-steps/release/vcs-utils.gradle b/build-steps/release/vcs-utils.gradle index 0b50d1a55c..6ac6aa0867 100644 --- a/build-steps/release/vcs-utils.gradle +++ b/build-steps/release/vcs-utils.gradle @@ -1,6 +1,8 @@ +apply from: scriptRelativePath(this, 'process-utils.gradle') + ext.gitCheckOut = { String url, File targetDir, String branch = null -> def branchSuffix = branch ? " --branch ${branch}" : '' targetDir.deleteDir() targetDir.mkdirs() - ['sh', '-c', "git clone ${url}${branchSuffix} ${targetDir.absolutePath}"].execute().waitFor() + executeCommand(['sh', '-c', "git clone ${url}${branchSuffix} ${targetDir.absolutePath}"]) }