From 4d817ec5bf36d93de6991c3ea34943b9b1a6abf5 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 30 Sep 2020 15:04:35 +0200 Subject: [PATCH 01/10] Allow tests to get output from flank on windows --- .../src/test/kotlin/utils/CommandHelper.kt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/integration_tests/src/test/kotlin/utils/CommandHelper.kt b/integration_tests/src/test/kotlin/utils/CommandHelper.kt index 5e6f1848e4..3579f71b78 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -4,10 +4,19 @@ import java.io.File import java.util.concurrent.TimeUnit fun String.runCommand(workingDir: File): ProcessResult = ProcessBuilder(*split("\\s".toRegex()).toTypedArray()) - .directory(workingDir) - .redirectOutput(ProcessBuilder.Redirect.PIPE) - .redirectError(ProcessBuilder.Redirect.PIPE) - .start().run { - waitFor(60, TimeUnit.MINUTES) - ProcessResult(exitValue(), inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText()) - } + .directory(workingDir).run { + if(System.getProperty("os.name").startsWith("Windows")) redirectOutput(File("out.txt")) + .redirectError(File("err.txt")) + .start().run { + waitFor(60, TimeUnit.MINUTES) + ProcessResult(exitValue(), File("out.txt").readText() + File("err.txt").readText()) + } + else redirectOutput(ProcessBuilder.Redirect.PIPE) + .redirectError(ProcessBuilder.Redirect.PIPE) + .start().run { + waitFor(60, TimeUnit.MINUTES) + ProcessResult(exitValue(), inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText()) + } + + } + From b6f591cef3bc4fea67a5a7a3ce1e20cf663a5cc5 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 30 Sep 2020 16:41:13 +0200 Subject: [PATCH 02/10] Added non wsl windows workflow file --- .../workflows/windows-non-wsl-workflow.yml | 51 +++++++++++++++++++ .../src/test/kotlin/utils/CommandHelper.kt | 31 ++++++----- 2 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/windows-non-wsl-workflow.yml diff --git a/.github/workflows/windows-non-wsl-workflow.yml b/.github/workflows/windows-non-wsl-workflow.yml new file mode 100644 index 0000000000..d6d71a531d --- /dev/null +++ b/.github/workflows/windows-non-wsl-workflow.yml @@ -0,0 +1,51 @@ +name: Flank WSL + +on: + pull_request_review: + types: submitted + +jobs: + build: + # The type of runner that the job will run on + runs-on: windows-2019 + steps: + + - uses: actions/checkout@v2 + with: + submodules: true + + - uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-2-gradle-${{ hashFiles('**/*.gradle*') }} + restore-keys: | + ${{ runner.os }}-2-gradle- + + - name: Set GCLOUD_KEY for WINDOWS + shell: cmd + run: | + echo ${{ secrets.GCLOUD_KEY }} > gcloud_key.txt + + - name: Gradle clean build + shell: cmd + run: | + gradlew.bat clean build + + - name: Prepare Google Service Account + shell: cmd + run: | + set GCLOUD_DIR=".config/gcloud/" + mkdir %GCLOUD_DIR% + certutil -decode gcloud_key.txt %GCLOUD_DIR%application_default_credentials.json + + - name: Check pull request is approved + uses: jrylan/github-action-reviews-counter@main + with: + repo-token: '${{ secrets.GITHUB_TOKEN }}' + - name: Gradle Integration Tests Android + if: 'steps.reviews.outputs.approved >= 2 && steps.reviews.outputs.changes_requested == 0 && github.event.pull_request.draft == false' + uses: eskatos/gradle-command-action@v1 + env: + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} + with: + arguments: "--info :integration_tests:test --tests IntegrationTests.shouldMatchAndroidSuccessExitCodeAndPattern -Dflank-path=../test_runner/build/libs/flank.jar -Dyml-path=./src/test/resources/flank_android.yml" diff --git a/integration_tests/src/test/kotlin/utils/CommandHelper.kt b/integration_tests/src/test/kotlin/utils/CommandHelper.kt index 3579f71b78..0653bbd5eb 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -5,18 +5,23 @@ import java.util.concurrent.TimeUnit fun String.runCommand(workingDir: File): ProcessResult = ProcessBuilder(*split("\\s".toRegex()).toTypedArray()) .directory(workingDir).run { - if(System.getProperty("os.name").startsWith("Windows")) redirectOutput(File("out.txt")) - .redirectError(File("err.txt")) - .start().run { - waitFor(60, TimeUnit.MINUTES) - ProcessResult(exitValue(), File("out.txt").readText() + File("err.txt").readText()) - } - else redirectOutput(ProcessBuilder.Redirect.PIPE) - .redirectError(ProcessBuilder.Redirect.PIPE) - .start().run { - waitFor(60, TimeUnit.MINUTES) - ProcessResult(exitValue(), inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText()) - } - + if (System.getProperty("os.name").startsWith("Windows")) + redirectOutput(File(outputFileName)). + redirectError(File(errorFileName)). + start(). + run { + waitFor(processTimeout, TimeUnit.MINUTES) + ProcessResult(exitValue(), File(outputFileName).readText() + File(errorFileName).readText()) + } + else redirectOutput(ProcessBuilder.Redirect.PIPE). + redirectError(ProcessBuilder.Redirect.PIPE). + start(). + run { + waitFor(processTimeout, TimeUnit.MINUTES) + ProcessResult(exitValue(), inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText()) + } } +private const val outputFileName = "out.log" +private const val errorFileName = "error.log" +private const val processTimeout = 60L From c099c5a1924a62a2cbd058d343402fe471825fac Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 30 Sep 2020 16:52:09 +0200 Subject: [PATCH 03/10] Update windows-non-wsl-workflow.yml --- .github/workflows/windows-non-wsl-workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows-non-wsl-workflow.yml b/.github/workflows/windows-non-wsl-workflow.yml index d6d71a531d..1c27c69b08 100644 --- a/.github/workflows/windows-non-wsl-workflow.yml +++ b/.github/workflows/windows-non-wsl-workflow.yml @@ -34,9 +34,9 @@ jobs: - name: Prepare Google Service Account shell: cmd run: | - set GCLOUD_DIR=".config/gcloud/" + set GCLOUD_DIR="%HOMEPATH%/.config/gcloud/" mkdir %GCLOUD_DIR% - certutil -decode gcloud_key.txt %GCLOUD_DIR%application_default_credentials.json + echo certutil -decode gcloud_key.txt %GCLOUD_DIR%application_default_credentials.json - name: Check pull request is approved uses: jrylan/github-action-reviews-counter@main From 0a248602ff78ab868d66c84d3854dca09a6bf8fa Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 1 Oct 2020 11:27:42 +0200 Subject: [PATCH 04/10] Minor fixes for windows build --- .../src/test/kotlin/utils/CommandHelper.kt | 29 +++++++-------- test_runner/build.gradle.kts | 37 ++++++++++++------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/integration_tests/src/test/kotlin/utils/CommandHelper.kt b/integration_tests/src/test/kotlin/utils/CommandHelper.kt index 0653bbd5eb..3a275a941c 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -4,23 +4,20 @@ import java.io.File import java.util.concurrent.TimeUnit fun String.runCommand(workingDir: File): ProcessResult = ProcessBuilder(*split("\\s".toRegex()).toTypedArray()) - .directory(workingDir).run { - if (System.getProperty("os.name").startsWith("Windows")) - redirectOutput(File(outputFileName)). - redirectError(File(errorFileName)). - start(). - run { - waitFor(processTimeout, TimeUnit.MINUTES) - ProcessResult(exitValue(), File(outputFileName).readText() + File(errorFileName).readText()) - } - else redirectOutput(ProcessBuilder.Redirect.PIPE). - redirectError(ProcessBuilder.Redirect.PIPE). - start(). - run { - waitFor(processTimeout, TimeUnit.MINUTES) - ProcessResult(exitValue(), inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText()) - } + .directory(workingDir).run { + if (System.getProperty("os.name").startsWith("Windows")) + redirectOutput(File(outputFileName)).redirectError(File(errorFileName)).start().run { + waitFor(processTimeout, TimeUnit.MINUTES) + ProcessResult(exitValue(), File(outputFileName).readText() + File(errorFileName).readText()) + } + else redirectOutput(ProcessBuilder.Redirect.PIPE).redirectError(ProcessBuilder.Redirect.PIPE).start().run { + waitFor(processTimeout, TimeUnit.MINUTES) + ProcessResult( + exitValue(), + inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText() + ) } + } private const val outputFileName = "out.log" private const val errorFileName = "error.log" diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index 58b48de865..469fdfa1c6 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -159,10 +159,10 @@ jacoco { tasks.jacocoTestReport { classDirectories.setFrom( - fileTree("build/classes/kotlin/main").apply { - exclude("**/*\$run$1.class") - exclude("**/ftl/mock/*") - }) + fileTree("build/classes/kotlin/main").apply { + exclude("**/*\$run$1.class") + exclude("**/ftl/mock/*") + }) reports { xml.isEnabled = true @@ -274,7 +274,18 @@ tasks["check"].dependsOn(tasks["jacocoTestReport"], tasks["detekt"]) val updateFlank by tasks.registering(Exec::class) { group = "Build" description = "Update flank jar" - commandLine = listOf("./bash/update_flank.sh") + commandLine = if (System.getProperty("os.name").toLowerCase().contains("windows")) { + doLast { + copy {//due to security permissions copying files is restricted via bat files + from("./test_runner/build/libs/flank.jar") + into("./test_runner/bash/") + } + } + listOf("./bash/update_flank.bat") + } else { + listOf("./bash/update_flank.sh") + } + } val flankFullRun by tasks.registering(Exec::class) { @@ -307,17 +318,17 @@ tasks.create("applyProguard", proguard.gradle.ProGuardTask::class.java) { val generateCliAsciiDoc by tasks.registering(JavaExec::class) { dependsOn(tasks.classes) classpath( - configurations.compile, - configurations.annotationProcessor, - sourceSets["main"].runtimeClasspath + configurations.compile, + configurations.annotationProcessor, + sourceSets["main"].runtimeClasspath ) group = "Documentation" description = "Generate AsciiDoc manpage" main = "picocli.codegen.docgen.manpage.ManPageGenerator" args = listOf( - application.mainClass.get(), - "--outdir=${project.rootDir}/docs/ascii/", - "-v" + application.mainClass.get(), + "--outdir=${project.rootDir}/docs/ascii/", + "-v" ) } @@ -329,8 +340,8 @@ val processCliAsciiDoc by tasks.registering { file.apply { readLines().run { val toRemove = IntRange( - indexOf("// tag::picocli-generated-man-section-header[]"), - indexOf("// end::picocli-generated-man-section-header[]") + indexOf("// tag::picocli-generated-man-section-header[]"), + indexOf("// end::picocli-generated-man-section-header[]") ) filterIndexed { index, _ -> index !in toRemove } }.joinToString("\n").let { text -> From 4facfdcb6b9909be5f256a9ad6472e8c96251afa Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 1 Oct 2020 14:40:11 +0200 Subject: [PATCH 05/10] Neaten CommandHHelper and add misisng bat file --- .../src/test/kotlin/utils/CommandHelper.kt | 31 +++++++++++++------ test_runner/bash/update_flank.bat | 7 +++++ 2 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 test_runner/bash/update_flank.bat diff --git a/integration_tests/src/test/kotlin/utils/CommandHelper.kt b/integration_tests/src/test/kotlin/utils/CommandHelper.kt index 3a275a941c..67c512c36e 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -3,22 +3,33 @@ package utils import java.io.File import java.util.concurrent.TimeUnit + fun String.runCommand(workingDir: File): ProcessResult = ProcessBuilder(*split("\\s".toRegex()).toTypedArray()) .directory(workingDir).run { - if (System.getProperty("os.name").startsWith("Windows")) - redirectOutput(File(outputFileName)).redirectError(File(errorFileName)).start().run { - waitFor(processTimeout, TimeUnit.MINUTES) - ProcessResult(exitValue(), File(outputFileName).readText() + File(errorFileName).readText()) - } - else redirectOutput(ProcessBuilder.Redirect.PIPE).redirectError(ProcessBuilder.Redirect.PIPE).start().run { + redirectOutputForCompatibleOS().start().run { waitFor(processTimeout, TimeUnit.MINUTES) - ProcessResult( - exitValue(), - inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText() - ) + ProcessResult(exitValue(), getOsSpecificOutput()) } } +private fun Process.getOsSpecificOutput(): String { + return if (isWindows) { + File(outputFileName).readText() + File(errorFileName).readText() + } else { + inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText() + } +} + +private fun ProcessBuilder.redirectOutputForCompatibleOS(): ProcessBuilder { + return if (isWindows) { + redirectOutput(File(outputFileName)).redirectError(File(errorFileName)) + } else { + redirectOutput(ProcessBuilder.Redirect.PIPE).redirectError(ProcessBuilder.Redirect.PIPE) + } +} + +private val isWindows = System.getProperty("os.name").startsWith("Windows") + private const val outputFileName = "out.log" private const val errorFileName = "error.log" private const val processTimeout = 60L diff --git a/test_runner/bash/update_flank.bat b/test_runner/bash/update_flank.bat new file mode 100644 index 0000000000..be3450420a --- /dev/null +++ b/test_runner/bash/update_flank.bat @@ -0,0 +1,7 @@ + +for %%F in (%filename%) do set dirname=%%~dpF +echo "%dirname%" +cd .. +cd .. +call gradlew.bat clean assemble shadowjar +cd test_runner\bash \ No newline at end of file From 274e0c605464f0ec43600b65d62177793eb13dd6 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 1 Oct 2020 14:53:31 +0200 Subject: [PATCH 06/10] Name change --- .github/workflows/windows-non-wsl-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows-non-wsl-workflow.yml b/.github/workflows/windows-non-wsl-workflow.yml index 1c27c69b08..ab6dfa3b04 100644 --- a/.github/workflows/windows-non-wsl-workflow.yml +++ b/.github/workflows/windows-non-wsl-workflow.yml @@ -1,4 +1,4 @@ -name: Flank WSL +name: Flank Windows on: pull_request_review: From c3030cd5796167de241ae0f3654c9a83d1b79e04 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 1 Oct 2020 16:15:15 +0200 Subject: [PATCH 07/10] PR comments 1 --- .../src/test/kotlin/utils/CommandHelper.kt | 12 ++++++------ test_runner/bash/update_flank.bat | 2 +- test_runner/build.gradle.kts | 13 ++++++------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/integration_tests/src/test/kotlin/utils/CommandHelper.kt b/integration_tests/src/test/kotlin/utils/CommandHelper.kt index 67c512c36e..a436c6b5ea 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -5,12 +5,12 @@ import java.util.concurrent.TimeUnit fun String.runCommand(workingDir: File): ProcessResult = ProcessBuilder(*split("\\s".toRegex()).toTypedArray()) - .directory(workingDir).run { - redirectOutputForCompatibleOS().start().run { - waitFor(processTimeout, TimeUnit.MINUTES) - ProcessResult(exitValue(), getOsSpecificOutput()) - } - } + .directory(workingDir).startProcess() + +private fun ProcessBuilder.startProcess() = start().run { + waitFor(processTimeout, TimeUnit.MINUTES) + ProcessResult(exitValue(), getOsSpecificOutput()) +} private fun Process.getOsSpecificOutput(): String { return if (isWindows) { diff --git a/test_runner/bash/update_flank.bat b/test_runner/bash/update_flank.bat index be3450420a..6f4d73a8c5 100644 --- a/test_runner/bash/update_flank.bat +++ b/test_runner/bash/update_flank.bat @@ -4,4 +4,4 @@ echo "%dirname%" cd .. cd .. call gradlew.bat clean assemble shadowjar -cd test_runner\bash \ No newline at end of file +cd test_runner\bash diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index 469fdfa1c6..cc3398f90a 100644 --- a/test_runner/build.gradle.kts +++ b/test_runner/build.gradle.kts @@ -158,11 +158,10 @@ jacoco { } tasks.jacocoTestReport { - classDirectories.setFrom( - fileTree("build/classes/kotlin/main").apply { - exclude("**/*\$run$1.class") - exclude("**/ftl/mock/*") - }) + classDirectories.setFrom(fileTree("build/classes/kotlin/main").apply { + exclude("**/*\$run$1.class") + exclude("**/ftl/mock/*") + }) reports { xml.isEnabled = true @@ -340,8 +339,8 @@ val processCliAsciiDoc by tasks.registering { file.apply { readLines().run { val toRemove = IntRange( - indexOf("// tag::picocli-generated-man-section-header[]"), - indexOf("// end::picocli-generated-man-section-header[]") + indexOf("// tag::picocli-generated-man-section-header[]"), + indexOf("// end::picocli-generated-man-section-header[]") ) filterIndexed { index, _ -> index !in toRemove } }.joinToString("\n").let { text -> From e8516ca68da8eb6b8bfcbde92418b8db817d0384 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 1 Oct 2020 16:19:07 +0200 Subject: [PATCH 08/10] PR comments 2 --- integration_tests/src/test/kotlin/utils/CommandHelper.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration_tests/src/test/kotlin/utils/CommandHelper.kt b/integration_tests/src/test/kotlin/utils/CommandHelper.kt index a436c6b5ea..c5a8768256 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -5,7 +5,8 @@ import java.util.concurrent.TimeUnit fun String.runCommand(workingDir: File): ProcessResult = ProcessBuilder(*split("\\s".toRegex()).toTypedArray()) - .directory(workingDir).startProcess() + .directory(workingDir).redirectOutputForCompatibleOS().startProcess() + private fun ProcessBuilder.startProcess() = start().run { waitFor(processTimeout, TimeUnit.MINUTES) From a8c48f3c84106c3d2a5cb239816be9fc454fbb37 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 1 Oct 2020 16:41:40 +0200 Subject: [PATCH 09/10] Return type removal --- .../src/test/kotlin/utils/CommandHelper.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/integration_tests/src/test/kotlin/utils/CommandHelper.kt b/integration_tests/src/test/kotlin/utils/CommandHelper.kt index c5a8768256..2597962ca9 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -21,12 +21,10 @@ private fun Process.getOsSpecificOutput(): String { } } -private fun ProcessBuilder.redirectOutputForCompatibleOS(): ProcessBuilder { - return if (isWindows) { - redirectOutput(File(outputFileName)).redirectError(File(errorFileName)) - } else { - redirectOutput(ProcessBuilder.Redirect.PIPE).redirectError(ProcessBuilder.Redirect.PIPE) - } +private fun ProcessBuilder.redirectOutputForCompatibleOS() = if (isWindows) { + redirectOutput(File(outputFileName)).redirectError(File(errorFileName)) +} else { + redirectOutput(ProcessBuilder.Redirect.PIPE).redirectError(ProcessBuilder.Redirect.PIPE) } private val isWindows = System.getProperty("os.name").startsWith("Windows") From 3db97940af4ac80d1d6c9ea85e07c67c5ce62023 Mon Sep 17 00:00:00 2001 From: Michael Wright Date: Thu, 1 Oct 2020 17:15:23 +0200 Subject: [PATCH 10/10] Return type removal #2 --- .../src/test/kotlin/utils/CommandHelper.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/integration_tests/src/test/kotlin/utils/CommandHelper.kt b/integration_tests/src/test/kotlin/utils/CommandHelper.kt index 2597962ca9..78a29fcddd 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -13,12 +13,10 @@ private fun ProcessBuilder.startProcess() = start().run { ProcessResult(exitValue(), getOsSpecificOutput()) } -private fun Process.getOsSpecificOutput(): String { - return if (isWindows) { - File(outputFileName).readText() + File(errorFileName).readText() - } else { - inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText() - } +private fun Process.getOsSpecificOutput() = if (isWindows) { + File(outputFileName).readText() + File(errorFileName).readText() +} else { + inputStream.bufferedReader().readText() + this.errorStream.bufferedReader().readText() } private fun ProcessBuilder.redirectOutputForCompatibleOS() = if (isWindows) {