-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
133 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugins { | ||
kotlin("jvm") | ||
id("org.jetbrains.dokka") version "1.9.10" | ||
} | ||
apply(plugin = "org.gradle.kotlin.kotlin-dsl") | ||
|
||
description = "Configures Gradle Release plugin for usage in CI" | ||
|
||
dependencies { | ||
implementation("net.researchgate", "gradle-release", "3.0.2") | ||
} |
54 changes: 54 additions & 0 deletions
54
release/src/main/kotlin/com/bakdata/gradle/ReleasePlugin.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,54 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2024 bakdata GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.bakdata.gradle | ||
|
||
import net.researchgate.release.ReleaseExtension | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.apply | ||
import org.gradle.kotlin.dsl.configure | ||
|
||
class ReleasePlugin : Plugin<Project> { | ||
|
||
override fun apply(rootProject: Project) { | ||
if (rootProject.parent != null) { | ||
throw GradleException("Apply this plugin only to the top-level project.") | ||
} | ||
|
||
with(rootProject) { | ||
apply(plugin = "net.researchgate.release") | ||
|
||
val disablePushToRemote: String? = project.property("disablePushToRemote") as? String | ||
disablePushToRemote?.let { | ||
configure<ReleaseExtension> { | ||
git { | ||
pushToRemote.set(!it.toBoolean()) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.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,66 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2024 bakdata GmbH | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.bakdata.gradle | ||
|
||
import net.researchgate.release.ReleasePlugin | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.Assertions.assertThatCode | ||
import org.assertj.core.api.Condition | ||
import org.assertj.core.api.SoftAssertions | ||
import org.gradle.api.Project | ||
import org.gradle.api.internal.project.DefaultProject | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.jupiter.api.Test | ||
|
||
internal class ReleasePluginTest { | ||
|
||
private fun Project.evaluate() { | ||
(this as DefaultProject).evaluate() | ||
} | ||
|
||
@Test | ||
fun testSingleModuleProjectWithJavaFirst() { | ||
val project = ProjectBuilder.builder().build() | ||
|
||
assertThatCode { | ||
project.pluginManager.apply("com.bakdata.release") | ||
project.evaluate() | ||
}.doesNotThrowAnyException() | ||
Check failure on line 50 in release/src/test/kotlin/com/bakdata/gradle/ReleasePluginTest.kt GitHub Actions / JUnit Test ReportReleasePluginTest.testSingleModuleProjectWithJavaFirst()
Raw output
|
||
|
||
SoftAssertions.assertSoftly { softly -> | ||
softly.assertThat(project.plugins) | ||
.haveExactly(1, Condition({ it is ReleasePlugin }, "Has release plugin")) | ||
} | ||
} | ||
|
||
@Test | ||
fun testWrongApplicationInMultiModuleProject() { | ||
val parent = ProjectBuilder.builder().withName("parent").build() | ||
val child1 = ProjectBuilder.builder().withName("child1").withParent(parent).build() | ||
|
||
assertThatCode { child1.pluginManager.apply("com.bakdata.release") } | ||
.satisfies { assertThat(it.cause).hasMessageContaining("top-level project") } | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
release/src/test/resources/META-INF/gradle-plugins/com.bakdata.release.properties
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 @@ | ||
implementation-class=com.bakdata.gradle.ReleasePlugin |
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