diff --git a/release_notes.md b/release_notes.md index 5874fa5042..04645a3073 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)) - [#759](https://github.com/Flank/flank/pull/759) Add shard name for uploaded xctestrun files. ([pawelpasterz](https://github.com/pawelpasterz)) - [#755](https://github.com/Flank/flank/pull/755) Remove ascii doc generated section header. ([jan-gogo](https://github.com/jan-gogo)) - [#731](https://github.com/Flank/flank/pull/731) Refactor jUnit HTML report. ([Writhe](https://github.com/Writhe)) diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index d66895a590..646ad2aaf4 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 @@ -137,9 +138,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 } @@ -278,3 +280,25 @@ tasks.assemble { dependsOn(processCliAsciiDoc) } // end --- ASCII doc generation --- + +val updateVersion by tasks.registering { + shouldRunAfter(tasks.processResources) + if (!runningOnBitrise) doLast { + 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() +} 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) + } } } }