diff --git a/.github/workflows/windows-non-wsl-workflow.yml b/.github/workflows/windows-non-wsl-workflow.yml new file mode 100644 index 0000000000..ab6dfa3b04 --- /dev/null +++ b/.github/workflows/windows-non-wsl-workflow.yml @@ -0,0 +1,51 @@ +name: Flank Windows + +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="%HOMEPATH%/.config/gcloud/" + mkdir %GCLOUD_DIR% + 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 + 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 5e6f1848e4..78a29fcddd 100644 --- a/integration_tests/src/test/kotlin/utils/CommandHelper.kt +++ b/integration_tests/src/test/kotlin/utils/CommandHelper.kt @@ -3,11 +3,30 @@ package utils 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).redirectOutputForCompatibleOS().startProcess() + + +private fun ProcessBuilder.startProcess() = start().run { + waitFor(processTimeout, TimeUnit.MINUTES) + ProcessResult(exitValue(), getOsSpecificOutput()) +} + +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) { + 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..6f4d73a8c5 --- /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 diff --git a/test_runner/build.gradle.kts b/test_runner/build.gradle.kts index 58b48de865..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 @@ -274,7 +273,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 +317,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" ) }