Skip to content

Commit 8bca33f

Browse files
authored
chore: extract duplicate version checking to convention plugin (#1488)
1 parent acd4fdc commit 8bca33f

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package buildsrc.convention
2+
3+
import org.gradle.api.Task
4+
import org.gradle.kotlin.dsl.registering
5+
import org.gradle.kotlin.dsl.getValue
6+
7+
val validateDuplicatedVersion by tasks.registering(Task::class) {
8+
// These properties of a project need to be resolved before the 'doLast' block because otherwise, Gradle
9+
// configuration cache cannot be used.
10+
val rootDir = rootDir
11+
val version = version
12+
13+
doLast {
14+
require(
15+
rootDir.resolve("mkdocs.yml").readText()
16+
.contains(" version: $version")
17+
) { "Library version stated in the docs should be equal to $version!" }
18+
require(
19+
rootDir.resolve("github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/docsnippets/GettingStartedSnippets.kt").readText()
20+
.contains("\"io.github.typesafegithub:github-workflows-kt:$version\"")
21+
) { "Library version stated in github-workflows-kt/src/test/.../GettingStarted.kt should be equal to $version!" }
22+
require(
23+
rootDir.resolve(".github/workflows/end-to-end-tests.main.kts").readText()
24+
.contains("\"io.github.typesafegithub:github-workflows-kt:$version\"")
25+
) { "Library version stated in end-to-end-tests.main.kts should be equal to $version!" }
26+
require(
27+
rootDir.resolve(".github/workflows/end-to-end-tests.main.kts").readText()
28+
.contains("\"io.github.typesafegithub:action-updates-checker:$version\"")
29+
) { "Library version stated in end-to-end-tests.main.kts should be equal to $version!" }
30+
require(
31+
rootDir.resolve("images/teaser-with-newest-version.svg").readText()
32+
.contains("\"io.github.typesafegithub:github-workflows-kt:$version\"")
33+
) { "Library version stated in the teaser image shiuld be equal to $version!" }
34+
}
35+
}
36+
37+
project.tasks.getByName("check") {
38+
dependsOn(validateDuplicatedVersion)
39+
}

github-workflows-kt/build.gradle.kts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.jmailen.gradle.kotlinter.tasks.ConfigurableKtLintTask
44
plugins {
55
buildsrc.convention.`kotlin-jvm`
66
buildsrc.convention.publishing
7+
buildsrc.convention.`duplicate-versions`
78

89
kotlin("plugin.serialization")
910

@@ -70,40 +71,6 @@ tasks.formatKotlinMain {
7071
kotlinterConfig()
7172
}
7273

73-
val validateDuplicatedVersion by tasks.creating<Task> {
74-
// These properties of a project need to be resolved before the 'doLast' block because otherwise, Gradle
75-
// configuration cache cannot be used.
76-
val rootDir = rootDir
77-
val version = version
78-
79-
doLast {
80-
require(
81-
rootDir.resolve("mkdocs.yml").readText()
82-
.contains(" version: $version")
83-
) { "Library version stated in the docs should be equal to $version!" }
84-
require(
85-
rootDir.resolve("github-workflows-kt/src/test/kotlin/io/github/typesafegithub/workflows/docsnippets/GettingStartedSnippets.kt").readText()
86-
.contains("\"io.github.typesafegithub:github-workflows-kt:$version\"")
87-
) { "Library version stated in github-workflows-kt/src/test/.../GettingStarted.kt should be equal to $version!" }
88-
require(
89-
rootDir.resolve(".github/workflows/end-to-end-tests.main.kts").readText()
90-
.contains("\"io.github.typesafegithub:github-workflows-kt:$version\"")
91-
) { "Library version stated in end-to-end-tests.main.kts should be equal to $version!" }
92-
require(
93-
rootDir.resolve(".github/workflows/end-to-end-tests.main.kts").readText()
94-
.contains("\"io.github.typesafegithub:action-updates-checker:$version\"")
95-
) { "Library version stated in end-to-end-tests.main.kts should be equal to $version!" }
96-
require(
97-
rootDir.resolve("images/teaser-with-newest-version.svg").readText()
98-
.contains("\"io.github.typesafegithub:github-workflows-kt:$version\"")
99-
) { "Library version stated in the teaser image shiuld be equal to $version!" }
100-
}
101-
}
102-
103-
tasks.check {
104-
dependsOn(validateDuplicatedVersion)
105-
}
106-
10774
pitest {
10875
junit5PluginVersion.set("1.1.0")
10976
excludedClasses.set(

0 commit comments

Comments
 (0)