From fb3aa155cb88789e1fc7b64903fd00bf028f9d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20G=C3=B3ral?= Date: Thu, 30 Apr 2020 21:21:36 +0200 Subject: [PATCH 1/4] Print version and revision before each command --- test_runner/build.gradle.kts | 14 ++++++++++++++ test_runner/src/main/kotlin/ftl/Main.kt | 15 ++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index f7a0757923..4d4549dbd8 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -258,3 +258,17 @@ tasks.assemble { dependsOn(generateManpageAsciiDoc) } // end --- ASCII doc generation --- + +val updateVersion by tasks.registering { + shouldRunAfter(tasks.processResources) + doLast { + File("${project.buildDir}/resources/main/version.txt").writeText("local_snapshot") + File("${project.buildDir}/resources/main/revision.txt").writeText( + String(Runtime.getRuntime().exec("git rev-parse HEAD").inputStream.readBytes()) + ) + } +} + +tasks.classes { + dependsOn(updateVersion) +} diff --git a/test_runner/src/main/kotlin/ftl/Main.kt b/test_runner/src/main/kotlin/ftl/Main.kt index 440d8af38d..1e2b7528a8 100644 --- a/test_runner/src/main/kotlin/ftl/Main.kt +++ b/test_runner/src/main/kotlin/ftl/Main.kt @@ -26,12 +26,8 @@ import picocli.CommandLine ) class Main : Runnable { override fun run() { - if (printVersion) { - println(readVersion()) - println(readRevision()) - } else { - CommandLine.usage(Main::class.java, System.out) - } + if (printVersion) return + CommandLine.usage(Main::class.java, System.out) } @CommandLine.Option(names = ["-v", "--version"], description = ["Prints the version"]) @@ -50,7 +46,12 @@ class Main : Runnable { // BugSnag opens a non-daemon thread which will keep the JVM process alive. // Flank must invoke exitProcess to exit cleanly. // https://github.com/bugsnag/bugsnag-java/issues/151 - withGlobalExceptionHandling { CommandLine(Main()).execute(*args) } + withGlobalExceptionHandling { + println("version: " + readVersion()) + println("revision: " + readRevision()) + println() + CommandLine(Main()).execute(*args) + } } } } From 337648c211ff5de00ff96080cd114bf5ef5f8ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20G=C3=B3ral?= Date: Thu, 30 Apr 2020 21:25:05 +0200 Subject: [PATCH 2/4] Update release_notes.md --- release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release_notes.md b/release_notes.md index 6949478fea..6f7469390f 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,4 +1,5 @@ ## next (unreleased) +- [#757](https://github.com/Flank/flank/pull/757) Print version and revision before each command. ([jan-gogo](https://github.com/jan-gogo)) - [#731](https://github.com/Flank/flank/pull/731) Refactor jUnit HTML report. ([Writhe](https://github.com/Writhe)) - [#754](https://github.com/Flank/flank/pull/754) Sync README.md flank.yml flank.ios.yml. ([jan-gogo](https://github.com/jan-gogo)) - [#746](https://github.com/Flank/flank/pull/746) Ignore apk with filtered out tests instead of failing. ([pawelpasterz](https://github.com/pawelpasterz)) From a08278f5c82554da155a14fdc7ef7fb2b8a3be03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20G=C3=B3ral?= Date: Thu, 30 Apr 2020 22:20:49 +0200 Subject: [PATCH 3/4] Do not override version.txt when running on bitrise job --- test_runner/build.gradle.kts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index 4d4549dbd8..01f32f3dbf 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -137,9 +137,10 @@ tasks.jacocoTestReport { } } +val runningOnBitrise get() = System.getenv("BITRISE_IO") != null + tasks.withType().configureEach { // https://devcenter.bitrise.io/builds/available-environment-variables/ - val runningOnBitrise = System.getenv("BITRISE_IO") != null kotlinOptions.allWarningsAsErrors = runningOnBitrise } @@ -261,7 +262,7 @@ tasks.assemble { val updateVersion by tasks.registering { shouldRunAfter(tasks.processResources) - doLast { + if (!runningOnBitrise) doLast { File("${project.buildDir}/resources/main/version.txt").writeText("local_snapshot") File("${project.buildDir}/resources/main/revision.txt").writeText( String(Runtime.getRuntime().exec("git rev-parse HEAD").inputStream.readBytes()) From 9ca57ded5e53cb00aae323be171c33d10f786331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20G=C3=B3ral?= Date: Fri, 1 May 2020 11:50:58 +0200 Subject: [PATCH 4/4] Use exec abstraction instead of direct Runtime --- test_runner/build.gradle.kts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index 01f32f3dbf..3e390a620a 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -5,6 +5,7 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.util.Date import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import java.io.ByteArrayOutputStream plugins { application @@ -263,13 +264,21 @@ tasks.assemble { val updateVersion by tasks.registering { shouldRunAfter(tasks.processResources) if (!runningOnBitrise) doLast { - File("${project.buildDir}/resources/main/version.txt").writeText("local_snapshot") - File("${project.buildDir}/resources/main/revision.txt").writeText( - String(Runtime.getRuntime().exec("git rev-parse HEAD").inputStream.readBytes()) - ) + File("$buildDir/resources/main/version.txt").writeText("local_snapshot") + File("$buildDir/resources/main/revision.txt").writeText(execAndGetStdout("git", "rev-parse", "HEAD")) } } tasks.classes { dependsOn(updateVersion) } + +fun execAndGetStdout(vararg args: String): String { + val stdout = ByteArrayOutputStream() + exec { + commandLine(*args) + standardOutput = stdout + workingDir = projectDir + } + return stdout.toString().trimEnd() +}