diff --git a/release/build.gradle.kts b/release/build.gradle.kts index 9727d45..5021820 100644 --- a/release/build.gradle.kts +++ b/release/build.gradle.kts @@ -8,4 +8,5 @@ description = "Configures Gradle Release plugin for usage in CI" dependencies { implementation("net.researchgate", "gradle-release", "3.0.2") + implementation("gradle.plugin.org.hildan.gradle", "gradle-github-changelog", "1.12.1") } diff --git a/release/src/main/kotlin/com/bakdata/gradle/ReleasePlugin.kt b/release/src/main/kotlin/com/bakdata/gradle/ReleasePlugin.kt index 65b9523..efaa962 100644 --- a/release/src/main/kotlin/com/bakdata/gradle/ReleasePlugin.kt +++ b/release/src/main/kotlin/com/bakdata/gradle/ReleasePlugin.kt @@ -30,12 +30,16 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.configure +import org.hildan.github.changelog.plugin.GitHubChangelogExtension class ReleasePlugin : Plugin { companion object { const val DISABLE_PUSH_TO_REMOTE = "release.disablePushToRemote" const val REQUIRE_BRANCH = "release.requireBranch" + const val GITHUB_REPOSITORY = "changelog.githubRepository" + const val FUTURE_VERSION_TAG = "changelog.futureVersionTag" + const val SINCE_TAG = "changelog.sinceTag" } override fun apply(rootProject: Project) { @@ -46,8 +50,8 @@ class ReleasePlugin : Plugin { with(rootProject) { apply(plugin = "net.researchgate.release") - val disablePushToRemote: String? = project.findProperty(DISABLE_PUSH_TO_REMOTE) as? String - val branch: String? = project.findProperty(REQUIRE_BRANCH) as? String + val disablePushToRemote: String? = project.findProperty(DISABLE_PUSH_TO_REMOTE)?.toString() + val branch: String? = project.findProperty(REQUIRE_BRANCH)?.toString() configure { git { if (disablePushToRemote?.toBoolean() == true) { @@ -58,6 +62,20 @@ class ReleasePlugin : Plugin { } } } + + apply(plugin = "org.hildan.github.changelog") + + configure { + project.findProperty(GITHUB_REPOSITORY)?.toString()?.also { + githubRepository = it + } + project.findProperty(FUTURE_VERSION_TAG)?.toString()?.also { + futureVersionTag = it + } + project.findProperty(SINCE_TAG)?.toString()?.also { + sinceTag = it + } + } } } } diff --git a/release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.kt b/release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.kt index 90c8af4..9fba2f9 100644 --- a/release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.kt +++ b/release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.kt @@ -25,7 +25,10 @@ package com.bakdata.gradle import com.bakdata.gradle.ReleasePlugin.Companion.DISABLE_PUSH_TO_REMOTE +import com.bakdata.gradle.ReleasePlugin.Companion.FUTURE_VERSION_TAG +import com.bakdata.gradle.ReleasePlugin.Companion.GITHUB_REPOSITORY import com.bakdata.gradle.ReleasePlugin.Companion.REQUIRE_BRANCH +import com.bakdata.gradle.ReleasePlugin.Companion.SINCE_TAG import net.researchgate.release.ReleaseExtension import net.researchgate.release.ReleasePlugin import org.assertj.core.api.Assertions.assertThat @@ -37,6 +40,8 @@ import org.gradle.api.internal.project.DefaultProject import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.findByType import org.gradle.testfixtures.ProjectBuilder +import org.hildan.github.changelog.plugin.GitHubChangelogExtension +import org.hildan.github.changelog.plugin.GitHubChangelogPlugin import org.junit.jupiter.api.Test internal class ReleasePluginTest { @@ -57,11 +62,18 @@ internal class ReleasePluginTest { SoftAssertions.assertSoftly { softly -> softly.assertThat(project.plugins) .haveExactly(1, Condition({ it is ReleasePlugin }, "Has release plugin")) + .haveExactly(1, Condition({ it is GitHubChangelogPlugin }, "Has changelog plugin")) softly.assertThat(project.extensions.findByType()?.git) .satisfies { softly.assertThat(it?.pushToRemote?.get()).isEqualTo("origin") softly.assertThat(it?.requireBranch?.get()).isEqualTo("main") } + softly.assertThat(project.extensions.findByType()) + .satisfies { + softly.assertThat(it?.githubRepository).isNull() + softly.assertThat(it?.futureVersionTag).isNull() + softly.assertThat(it?.sinceTag).isNull() + } } } @@ -113,6 +125,54 @@ internal class ReleasePluginTest { } } + @Test + fun testRepository() { + val project = ProjectBuilder.builder().build() + + assertThatCode { + project.extra.set(GITHUB_REPOSITORY, "my-repo") + project.pluginManager.apply("com.bakdata.release") + project.evaluate() + }.doesNotThrowAnyException() + + SoftAssertions.assertSoftly { softly -> + softly.assertThat(project.extensions.findByType()?.githubRepository) + .isEqualTo("my-repo") + } + } + + @Test + fun testFutureVersionTag() { + val project = ProjectBuilder.builder().build() + + assertThatCode { + project.extra.set(FUTURE_VERSION_TAG, "my-tag") + project.pluginManager.apply("com.bakdata.release") + project.evaluate() + }.doesNotThrowAnyException() + + SoftAssertions.assertSoftly { softly -> + softly.assertThat(project.extensions.findByType()?.futureVersionTag) + .isEqualTo("my-tag") + } + } + + @Test + fun testSinceTag() { + val project = ProjectBuilder.builder().build() + + assertThatCode { + project.extra.set(SINCE_TAG, "my-tag") + project.pluginManager.apply("com.bakdata.release") + project.evaluate() + }.doesNotThrowAnyException() + + SoftAssertions.assertSoftly { softly -> + softly.assertThat(project.extensions.findByType()?.sinceTag) + .isEqualTo("my-tag") + } + } + @Test fun testWrongApplicationInMultiModuleProject() { val parent = ProjectBuilder.builder().withName("parent").build()