Skip to content

Commit

Permalink
feat: Android integration tests run on non wsl windows (#1175)
Browse files Browse the repository at this point in the history
* Allow tests to get output from flank on windows

* Added non wsl windows workflow file

* Update windows-non-wsl-workflow.yml

* Minor fixes for windows build

* Neaten CommandHHelper and add misisng bat file

* Name change

* PR comments 1

* PR comments 2

* Return type removal

* Return type removal #2

Co-authored-by: Michael Wright <[email protected]>
  • Loading branch information
adamfilipow92 and Sloox authored Oct 5, 2020
1 parent 563d155 commit c6bc9fb
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 19 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/windows-non-wsl-workflow.yml
Original file line number Diff line number Diff line change
@@ -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"
33 changes: 26 additions & 7 deletions integration_tests/src/test/kotlin/utils/CommandHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test_runner/bash/update_flank.bat
Original file line number Diff line number Diff line change
@@ -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
34 changes: 22 additions & 12 deletions test_runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
)
}

Expand Down

0 comments on commit c6bc9fb

Please sign in to comment.