forked from Kotlin/kotlinx-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardise and verify the minimum supported Gradle version (Kotlin#204)
- store the minimal supported Gradle version in libs.versions.toml - Add a new CheckReadmeTask to check that the README is up-to-date - update code for generating plugin constants into a new file, rather than editing the plugin file in-place - add integration tests for checking the supported Gradle version, and logged warning
- Loading branch information
Showing
12 changed files
with
158 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package tasks | ||
|
||
import org.gradle.api.* | ||
import org.gradle.api.file.* | ||
import org.gradle.api.provider.* | ||
import org.gradle.api.tasks.* | ||
import org.gradle.api.tasks.PathSensitivity.* | ||
|
||
abstract class CheckReadmeTask : DefaultTask() { | ||
@get:Input | ||
abstract val minSupportedGradleVersion: Property<String> | ||
|
||
@get:InputFile | ||
@get:PathSensitive(RELATIVE) | ||
abstract val readme: RegularFileProperty | ||
|
||
@TaskAction | ||
fun execute() { | ||
val readme = readme.get().asFile | ||
val readmeContents = readme.readText() | ||
|
||
val minSupportedGradleVersion = minSupportedGradleVersion.get() | ||
|
||
val matches = Regex("Gradle (?<version>[^ ]+) or newer").findAll(readmeContents).toList() | ||
|
||
require(matches.size >= 1) { | ||
""" | ||
$readme does not contain correct min supported Gradle version. | ||
${matches.size} matches found. | ||
""".trimIndent() | ||
} | ||
|
||
matches.forEach { match -> | ||
val version = match.groups["version"]?.value ?: error("Regex failed - could not find version") | ||
require(minSupportedGradleVersion == version) { | ||
""" | ||
$readme does not contain correct min supported Gradle version | ||
Actual: ${match.value} | ||
Expected: Gradle $minSupportedGradleVersion or newer | ||
""".trimIndent() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[versions] | ||
|
||
minSupportedGradle = "7.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
integration/src/main/kotlin/kotlinx/benchmark/integration/Runner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
integration/src/test/kotlin/kotlinx/benchmark/integration/SupportedGradleVersionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package kotlinx.benchmark.integration | ||
|
||
import org.gradle.util.GradleVersion | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
class SupportedGradleVersionTest : GradleTest() { | ||
|
||
/** The min supported version used in build scripts, provided as a system property. */ | ||
private val minSupportedGradleVersion = System.getProperty("minSupportedGradleVersion") | ||
private val warningMessage = | ||
"JetBrains Gradle Benchmarks plugin requires Gradle version ${GradleTestVersion.MinSupportedGradleVersion.versionString}" | ||
|
||
@Test | ||
fun `test MinSupportedGradleVersion matches the version used in build scripts`() { | ||
assertEquals(minSupportedGradleVersion, GradleTestVersion.MinSupportedGradleVersion.versionString) | ||
} | ||
|
||
@Test | ||
fun `test MinSupportedGradleVersion is greater than UnsupportedGradleVersion`() { | ||
// verify the test data is valid | ||
assertTrue( | ||
GradleVersion.version(GradleTestVersion.MinSupportedGradleVersion.versionString) > | ||
GradleVersion.version(GradleTestVersion.UnsupportedGradleVersion.versionString) | ||
) | ||
} | ||
|
||
@Test | ||
fun `when using min supported Gradle version, expect no warning`() { | ||
val runner = project("kotlin-multiplatform", gradleVersion = GradleTestVersion.MinSupportedGradleVersion) | ||
|
||
runner.run(":help", "-q") { | ||
assertOutputDoesNotContain(warningMessage) | ||
} | ||
} | ||
|
||
@Test | ||
fun `when using unsupported Gradle version, expect warning`() { | ||
val runner = project("kotlin-multiplatform", gradleVersion = GradleTestVersion.UnsupportedGradleVersion) | ||
|
||
runner.run(":help", "-q") { | ||
assertOutputContains(warningMessage) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters