Skip to content

Commit

Permalink
Configure changelog plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp94831 committed Mar 4, 2024
1 parent 255ab68 commit 696283c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
1 change: 1 addition & 0 deletions release/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
22 changes: 20 additions & 2 deletions release/src/main/kotlin/com/bakdata/gradle/ReleasePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project> {

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) {
Expand All @@ -46,8 +50,8 @@ class ReleasePlugin : Plugin<Project> {
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<ReleaseExtension> {
git {
if (disablePushToRemote?.toBoolean() == true) {
Expand All @@ -58,6 +62,20 @@ class ReleasePlugin : Plugin<Project> {
}
}
}

apply(plugin = "org.hildan.github.changelog")

configure<GitHubChangelogExtension> {
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
}
}
}
}
}
60 changes: 60 additions & 0 deletions release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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<ReleaseExtension>()?.git)
.satisfies {
softly.assertThat(it?.pushToRemote?.get()).isEqualTo("origin")
softly.assertThat(it?.requireBranch?.get()).isEqualTo("main")
}
softly.assertThat(project.extensions.findByType<GitHubChangelogExtension>())
.satisfies {
softly.assertThat(it?.githubRepository).isNull()
softly.assertThat(it?.futureVersionTag).isNull()
softly.assertThat(it?.sinceTag).isNull()
}
}
}

Expand Down Expand Up @@ -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<GitHubChangelogExtension>()?.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<GitHubChangelogExtension>()?.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<GitHubChangelogExtension>()?.sinceTag)
.isEqualTo("my-tag")
}
}

@Test
fun testWrongApplicationInMultiModuleProject() {
val parent = ProjectBuilder.builder().withName("parent").build()
Expand Down

0 comments on commit 696283c

Please sign in to comment.