Skip to content

Commit 9ca569d

Browse files
authored
Configure changelog plugin (#49)
1 parent a80994c commit 9ca569d

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

release/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ description = "Configures Gradle Release plugin for usage in CI"
88

99
dependencies {
1010
implementation("net.researchgate", "gradle-release", "3.0.2")
11+
implementation("gradle.plugin.org.hildan.gradle", "gradle-github-changelog", "1.12.1")
1112
}

release/src/main/kotlin/com/bakdata/gradle/ReleasePlugin.kt

+20-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ import org.gradle.api.Plugin
3030
import org.gradle.api.Project
3131
import org.gradle.kotlin.dsl.apply
3232
import org.gradle.kotlin.dsl.configure
33+
import org.hildan.github.changelog.plugin.GitHubChangelogExtension
3334

3435
class ReleasePlugin : Plugin<Project> {
3536

3637
companion object {
3738
const val DISABLE_PUSH_TO_REMOTE = "release.disablePushToRemote"
3839
const val REQUIRE_BRANCH = "release.requireBranch"
40+
const val GITHUB_REPOSITORY = "changelog.githubRepository"
41+
const val FUTURE_VERSION_TAG = "changelog.futureVersionTag"
42+
const val SINCE_TAG = "changelog.sinceTag"
3943
}
4044

4145
override fun apply(rootProject: Project) {
@@ -46,8 +50,8 @@ class ReleasePlugin : Plugin<Project> {
4650
with(rootProject) {
4751
apply(plugin = "net.researchgate.release")
4852

49-
val disablePushToRemote: String? = project.findProperty(DISABLE_PUSH_TO_REMOTE) as? String
50-
val branch: String? = project.findProperty(REQUIRE_BRANCH) as? String
53+
val disablePushToRemote: String? = project.findProperty(DISABLE_PUSH_TO_REMOTE)?.toString()
54+
val branch: String? = project.findProperty(REQUIRE_BRANCH)?.toString()
5155
configure<ReleaseExtension> {
5256
git {
5357
if (disablePushToRemote?.toBoolean() == true) {
@@ -58,6 +62,20 @@ class ReleasePlugin : Plugin<Project> {
5862
}
5963
}
6064
}
65+
66+
apply(plugin = "org.hildan.github.changelog")
67+
68+
configure<GitHubChangelogExtension> {
69+
project.findProperty(GITHUB_REPOSITORY)?.toString()?.also {
70+
githubRepository = it
71+
}
72+
project.findProperty(FUTURE_VERSION_TAG)?.toString()?.also {
73+
futureVersionTag = it
74+
}
75+
project.findProperty(SINCE_TAG)?.toString()?.also {
76+
sinceTag = it
77+
}
78+
}
6179
}
6280
}
6381
}

release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.kt

+60
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
package com.bakdata.gradle
2626

2727
import com.bakdata.gradle.ReleasePlugin.Companion.DISABLE_PUSH_TO_REMOTE
28+
import com.bakdata.gradle.ReleasePlugin.Companion.FUTURE_VERSION_TAG
29+
import com.bakdata.gradle.ReleasePlugin.Companion.GITHUB_REPOSITORY
2830
import com.bakdata.gradle.ReleasePlugin.Companion.REQUIRE_BRANCH
31+
import com.bakdata.gradle.ReleasePlugin.Companion.SINCE_TAG
2932
import net.researchgate.release.ReleaseExtension
3033
import net.researchgate.release.ReleasePlugin
3134
import org.assertj.core.api.Assertions.assertThat
@@ -37,6 +40,8 @@ import org.gradle.api.internal.project.DefaultProject
3740
import org.gradle.kotlin.dsl.extra
3841
import org.gradle.kotlin.dsl.findByType
3942
import org.gradle.testfixtures.ProjectBuilder
43+
import org.hildan.github.changelog.plugin.GitHubChangelogExtension
44+
import org.hildan.github.changelog.plugin.GitHubChangelogPlugin
4045
import org.junit.jupiter.api.Test
4146

4247
internal class ReleasePluginTest {
@@ -57,11 +62,18 @@ internal class ReleasePluginTest {
5762
SoftAssertions.assertSoftly { softly ->
5863
softly.assertThat(project.plugins)
5964
.haveExactly(1, Condition({ it is ReleasePlugin }, "Has release plugin"))
65+
.haveExactly(1, Condition({ it is GitHubChangelogPlugin }, "Has changelog plugin"))
6066
softly.assertThat(project.extensions.findByType<ReleaseExtension>()?.git)
6167
.satisfies {
6268
softly.assertThat(it?.pushToRemote?.get()).isEqualTo("origin")
6369
softly.assertThat(it?.requireBranch?.get()).isEqualTo("main")
6470
}
71+
softly.assertThat(project.extensions.findByType<GitHubChangelogExtension>())
72+
.satisfies {
73+
softly.assertThat(it?.githubRepository).isNull()
74+
softly.assertThat(it?.futureVersionTag).isNull()
75+
softly.assertThat(it?.sinceTag).isNull()
76+
}
6577
}
6678
}
6779

@@ -113,6 +125,54 @@ internal class ReleasePluginTest {
113125
}
114126
}
115127

128+
@Test
129+
fun testRepository() {
130+
val project = ProjectBuilder.builder().build()
131+
132+
assertThatCode {
133+
project.extra.set(GITHUB_REPOSITORY, "my-repo")
134+
project.pluginManager.apply("com.bakdata.release")
135+
project.evaluate()
136+
}.doesNotThrowAnyException()
137+
138+
SoftAssertions.assertSoftly { softly ->
139+
softly.assertThat(project.extensions.findByType<GitHubChangelogExtension>()?.githubRepository)
140+
.isEqualTo("my-repo")
141+
}
142+
}
143+
144+
@Test
145+
fun testFutureVersionTag() {
146+
val project = ProjectBuilder.builder().build()
147+
148+
assertThatCode {
149+
project.extra.set(FUTURE_VERSION_TAG, "my-tag")
150+
project.pluginManager.apply("com.bakdata.release")
151+
project.evaluate()
152+
}.doesNotThrowAnyException()
153+
154+
SoftAssertions.assertSoftly { softly ->
155+
softly.assertThat(project.extensions.findByType<GitHubChangelogExtension>()?.futureVersionTag)
156+
.isEqualTo("my-tag")
157+
}
158+
}
159+
160+
@Test
161+
fun testSinceTag() {
162+
val project = ProjectBuilder.builder().build()
163+
164+
assertThatCode {
165+
project.extra.set(SINCE_TAG, "my-tag")
166+
project.pluginManager.apply("com.bakdata.release")
167+
project.evaluate()
168+
}.doesNotThrowAnyException()
169+
170+
SoftAssertions.assertSoftly { softly ->
171+
softly.assertThat(project.extensions.findByType<GitHubChangelogExtension>()?.sinceTag)
172+
.isEqualTo("my-tag")
173+
}
174+
}
175+
116176
@Test
117177
fun testWrongApplicationInMultiModuleProject() {
118178
val parent = ProjectBuilder.builder().withName("parent").build()

0 commit comments

Comments
 (0)