Skip to content

Commit

Permalink
Remove disallowed use of project in commit task (#854)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
  • Loading branch information
SUPERCILEX committed Nov 7, 2021
1 parent aa73701 commit 47f649a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ internal abstract class CommitEdit @Inject constructor(
extension: PlayPublisherExtension,
private val executor: WorkerExecutor,
) : PublishTaskBase(extension) {
@TaskAction
fun commit() {
if (project.gradle.taskGraph.allTasks.any { it.state.failure != null }) {
logger.info("Build failed, skipping")
apiService.get().cleanup()
return
init {
onlyIf {
val buildFailed = project.gradle.taskGraph.allTasks.any { it.state.failure != null }
if (buildFailed) apiService.get().cleanup()
!buildFailed
}
}

@TaskAction
fun commit() {
executor.noIsolation().submit(Committer::class) {
paramsForBase(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.github.triplet.gradle.common.utils.safeCreateNewFile
import com.github.triplet.gradle.play.helpers.IntegrationTestBase
import com.github.triplet.gradle.play.helpers.SharedIntegrationTest
import com.google.common.truth.Truth.assertThat
import org.gradle.testkit.runner.TaskOutcome.SKIPPED
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.junit.jupiter.api.Test
import java.io.File
Expand Down Expand Up @@ -51,6 +52,30 @@ class CommitEditIntegrationTest : IntegrationTestBase(), SharedIntegrationTest {
assertThat(result.output).contains("commitEdit(foobar")
}

@Test
fun `Commit task is not run if build failed`() {
val editFile = File(appDir, "build/gpp/com.example.publisher.txt")
editFile.safeCreateNewFile().writeText("foobar")
editFile.marked("commit").safeCreateNewFile()

// language=gradle
val config = """
afterEvaluate {
tasks.named("promoteReleaseArtifact").configure {
doFirst {
throw new IllegalStateException("Dang :(")
}
}
}
"""
val result = executeExpectingFailure(config, "promoteReleaseArtifact")

result.requireTask(outcome = SKIPPED)
assertThat(result.output).doesNotContain("commitEdit(")
assertThat(editFile.exists()).isFalse()
assertThat(editFile.marked("commit").exists()).isFalse()
}

companion object {
@JvmStatic
fun installFactories() {
Expand Down

0 comments on commit 47f649a

Please sign in to comment.