Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable gradle configuration cache for tests #91

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

- uses: actions/checkout@v3

- uses: gradle/wrapper-validation-action@v1

- uses: gradle/gradle-build-action@v2
with:
gradle-version: ${{ matrix.gradle-version }}
Expand Down
23 changes: 12 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ plugins {
}

val setupPluginUpload by tasks.registering {
if (System.getenv("GITHUB_ACTION") == null) return@registering
if (!providers.environmentVariable("GITHUB_ACTION").isPresent) return@registering

val key = System.getenv(GRADLE_PUBLISH_KEY_ENV) ?: System.getProperty(GRADLE_PUBLISH_KEY)
val secret = System.getenv(GRADLE_PUBLISH_SECRET_ENV) ?: System.getProperty(GRADLE_PUBLISH_SECRET)
val key = providers.environmentVariable(GRADLE_PUBLISH_KEY_ENV)
.orElse(providers.systemProperty(GRADLE_PUBLISH_KEY))

if (key == null || secret == null) {
error("GRADLE_PUBLISH_KEY and/or GRADLE_PUBLISH_SECRET are not defined environment variables")
}
val secret = providers.environmentVariable(GRADLE_PUBLISH_SECRET_ENV)
.orElse(providers.systemProperty(GRADLE_PUBLISH_SECRET))

System.setProperty(GRADLE_PUBLISH_KEY, key)
System.setProperty(GRADLE_PUBLISH_SECRET, secret)
if (!key.isPresent || !secret.isPresent) {
error("GRADLE_PUBLISH_KEY and/or GRADLE_PUBLISH_SECRET are not defined environment or system variables")
}

// This is the git tag for a release
val githubRefName = System.getenv("GITHUB_REF_NAME")?.trimStart('v')
version = checkNotNull(githubRefName) { "No GITHUB_REF_NAME env value defined" }
val githubRefName = providers.environmentVariable("GITHUB_REF_NAME").map { it.trimStart('v') }
version = checkNotNull(githubRefName.orNull) { "No GITHUB_REF_NAME env value defined" }
}

tasks.named("publishPlugins") {
Expand Down Expand Up @@ -72,6 +72,7 @@ dependencies {

val kotlinVersion = "1.6.21"
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin-api:$kotlinVersion")

testCompileOnly("org.jetbrains:annotations:24.0.1")

Expand Down Expand Up @@ -101,7 +102,7 @@ detekt {
autoCorrect = true

buildUponDefaultConfig = true // preconfigure defaults
config.from("$rootDir/config/detekt-config.yml")
config.from("$rootDir/detekt.yaml")

allRules = false // activate all available (even unstable) rules.
}
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.configuration-cache=true
org.gradle.caching=true
19 changes: 15 additions & 4 deletions src/test/kotlin/org/assertj/generator/gradle/AssertExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ package org.assertj.generator.gradle
import org.assertj.core.api.AbstractObjectAssert
import org.gradle.testkit.runner.BuildTask
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.TaskOutcome.FROM_CACHE
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.gradle.testkit.runner.TaskOutcome.UP_TO_DATE

internal fun <SELF : AbstractObjectAssert<SELF, BuildTask?>> SELF.isSuccessful(): SELF = isOutcome(TaskOutcome.SUCCESS)
internal fun <SELF : AbstractObjectAssert<SELF, BuildTask?>> SELF.isUpToDate(): SELF = isOutcome(TaskOutcome.UP_TO_DATE)
internal fun <SELF : AbstractObjectAssert<SELF, BuildTask?>> SELF.isSuccessful(): SELF = isOutcome(SUCCESS)

private fun <SELF : AbstractObjectAssert<SELF, BuildTask?>> SELF.isOutcome(outcome: TaskOutcome): SELF {
extracting { it?.outcome }.`as` { "task.outcome == $outcome" }.isEqualTo(outcome)
internal fun <SELF : AbstractObjectAssert<SELF, BuildTask?>> SELF.isSuccessOrCached(): SELF = isOutcome(
SUCCESS,
FROM_CACHE
)

internal fun <SELF : AbstractObjectAssert<SELF, BuildTask?>> SELF.isUpToDate(): SELF = isOutcome(UP_TO_DATE)

private fun <SELF : AbstractObjectAssert<SELF, BuildTask?>> SELF.isOutcome(vararg outcomes: TaskOutcome): SELF {
extracting { it?.outcome }
.`as` { "task.outcome in { ${outcomes.joinToString(", ")} }" }
.isIn(outcomes.toSet())
return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ internal class IncrementalBuild {

val firstBuild = buildRunner.build()

assertThat(firstBuild.task(":generateAssertJ")).isSuccessful()
assertThat(firstBuild.task(":test")).isSuccessful()
assertThat(firstBuild.task(":generateAssertJ")).isSuccessOrCached()
assertThat(firstBuild.task(":test")).isSuccessOrCached()

root.assertFiles()

Expand All @@ -65,8 +65,8 @@ internal class IncrementalBuild {

val firstBuild = buildRunner.build()

assertThat(firstBuild.task(":generateAssertJ")).isSuccessful()
assertThat(firstBuild.task(":test")).isSuccessful()
assertThat(firstBuild.task(":generateAssertJ")).isSuccessOrCached()
assertThat(firstBuild.task(":test")).isSuccessOrCached()

// get files
root.assertFiles()
Expand Down
8 changes: 4 additions & 4 deletions src/test/kotlin/org/assertj/generator/gradle/SimpleBuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ internal class SimpleBuild {

val result = runner.withArguments("-i", "-s", "test").build()

assertThat(result.task(":generateAssertJ")).isSuccessful()
assertThat(result.task(":test")).isSuccessful()
assertThat(result.task(":generateAssertJ")).isSuccessOrCached()
assertThat(result.task(":test")).isSuccessOrCached()
}

@Test
Expand All @@ -62,8 +62,8 @@ internal class SimpleBuild {

val result = runner.withArguments("-i", "-s", "test").build()

assertThat(result.task(":generateAssertJ")).isSuccessful()
assertThat(result.task(":test")).isSuccessful()
assertThat(result.task(":generateAssertJ")).isSuccessOrCached()
assertThat(result.task(":test")).isSuccessOrCached()

val packagePath = root.toPath()
.resolve("build/generated-src/main-test/java")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class SkipPackageInfo {
.resolve("org/example")

@Test
@GradleProject("simple-build")
@GradleProject("skip-package-info")
fun `does not include package info file`(
@GradleProject.Root root: File,
@GradleProject.Runner runner: GradleRunner,
Expand Down
2 changes: 2 additions & 0 deletions src/test/projects/incremental-build/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.configuration-cache=true
org.gradle.caching=true
2 changes: 2 additions & 0 deletions src/test/projects/simple-build/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.configuration-cache=true
org.gradle.caching=true