Skip to content

Commit

Permalink
Fail build when fallback enabled and remote execution fails (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
skrugly authored Aug 26, 2020
1 parent dc93102 commit a39bbc4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
40 changes: 40 additions & 0 deletions plugin-test/src/test/kotlin/FallbackTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.gradle.testkit.runner.GradleRunner
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import java.io.FileWriter
import java.io.PrintWriter

Expand Down Expand Up @@ -52,6 +53,45 @@ object FallbackTest : Spek({
testResult.assertTaskSkipped("downloadFromRemote")
}
}

describe("successfully configured mirakle with fallback") {
beforeEachTest {
folder.newFile("mirakle_init.gradle")
.outputStream()
.let(::PrintWriter)
.use {
it.append(MIRAKLE_INIT_WITH_FOLDER(folder.root.canonicalPath).replace("fallback false", "fallback true"))
}
}

val gradleRunner by memoized {
GradleRunner.create()
.withProjectDir(folder.root)
.withGradleVersion(gradleVersion)
.forwardOutput()
.withArguments("-I", "mirakle_init.gradle", "tasks")
}

val buildFile by memoized { folder.newFile("build.gradle.kts") }
fun buildFileWriter() = PrintWriter(FileWriter(buildFile, true))

on("exception occurred on remote side") {
buildFileWriter().use { it.write(THROW) }
val testResult = gradleRunner.testFail()

it("should fail") {
testResult.assertBuildFailed()
}

it("should execute download task") {
testResult.assertTaskSucceed("downloadFromRemote")
}

it("should skip fallback task") {
testResult.assertTaskSkipped("fallback")
}
}
}
}
}
})
1 change: 1 addition & 0 deletions plugin-test/src/test/kotlin/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ apply plugin: Mirakle
rootProject {
mirakle {
host "localhost"
fallback false
remoteFolder "$remoteFolder/mirakle"
}
}
Expand Down
6 changes: 6 additions & 0 deletions plugin/src/main/kotlin/Mirakle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class Mirakle : Plugin<Gradle> {

execute.onlyIf { upload.execResult!!.exitValue == 0 }
download.onlyIf { upload.execResult!!.exitValue == 0 }

mirakle.doLast {
if (execute.didWork) {
execute.execResult!!.assertNormalExitValue()
}
}
}

gradle.supportAndroidStudioAdvancedProfiling(config, upload, execute, download)
Expand Down

0 comments on commit a39bbc4

Please sign in to comment.