Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print version and revision before each command #757

Merged
merged 6 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -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))
- [#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))
- [#754](https://github.com/Flank/flank/pull/754) Sync README.md flank.yml flank.ios.yml. ([jan-gogo](https://github.com/jan-gogo))
Expand Down
26 changes: 25 additions & 1 deletion test_runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,9 +138,10 @@ tasks.jacocoTestReport {
}
}

val runningOnBitrise get() = System.getenv("BITRISE_IO") != null

tasks.withType<KotlinCompile>().configureEach {
// https://devcenter.bitrise.io/builds/available-environment-variables/
val runningOnBitrise = System.getenv("BITRISE_IO") != null
kotlinOptions.allWarningsAsErrors = runningOnBitrise
}

Expand Down Expand Up @@ -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()
}
15 changes: 8 additions & 7 deletions test_runner/src/main/kotlin/ftl/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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)
}
}
}
}