From 764e07f6a892152e59a389e29c82fda1c07ec3bd Mon Sep 17 00:00:00 2001 From: Kyle Lehman Date: Fri, 9 Jun 2023 10:44:05 -0700 Subject: [PATCH] Creates github release convention (#13) * Creates github release convention * Fixes apiEndpoint --- .../src/main/kotlin/PluginAccessors.kt | 3 ++ ....polyworld.build.github-release.gradle.kts | 16 +++++++ .../build/PolyworldGithubReleaseExtension.kt | 22 ++++++++++ ...lyworldGradlePluginPluginFunctionalTest.kt | 43 +++++++++++++++++++ .../build/PolyworldGradlePluginPlugin.kt | 21 +++++++++ .../build/PolyworldGradlePluginPluginTest.kt | 22 ++++++++++ settings.gradle.kts | 1 - 7 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 conventions/src/main/kotlin/com.github.kyhule.polyworld.build.github-release.gradle.kts create mode 100644 conventions/src/main/kotlin/com/github/kyhule/polyworld/build/PolyworldGithubReleaseExtension.kt create mode 100644 plugin/src/functionalTest/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPluginFunctionalTest.kt create mode 100644 plugin/src/main/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPlugin.kt create mode 100644 plugin/src/test/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPluginTest.kt diff --git a/conventions/src/main/kotlin/PluginAccessors.kt b/conventions/src/main/kotlin/PluginAccessors.kt index 89aeabf..345644a 100644 --- a/conventions/src/main/kotlin/PluginAccessors.kt +++ b/conventions/src/main/kotlin/PluginAccessors.kt @@ -11,6 +11,9 @@ val PluginDependenciesSpec.`polyworld-android-lib`: PluginDependencySpec val PluginDependenciesSpec.`polyworld-root`: PluginDependencySpec get() = polyworld("root") +val PluginDependenciesSpec.`polyworld-github-release`: PluginDependencySpec + get() = polyworld("github-release") + val PluginDependenciesSpec.`polyworld-maven-publish`: PluginDependencySpec get() = polyworld("maven-publish") diff --git a/conventions/src/main/kotlin/com.github.kyhule.polyworld.build.github-release.gradle.kts b/conventions/src/main/kotlin/com.github.kyhule.polyworld.build.github-release.gradle.kts new file mode 100644 index 0000000..3b1ba00 --- /dev/null +++ b/conventions/src/main/kotlin/com.github.kyhule.polyworld.build.github-release.gradle.kts @@ -0,0 +1,16 @@ +import com.github.kyhule.polyworld.build.PolyworldGithubReleaseExtension + +plugins { + id("com.github.breadmoirai.github-release") +} + +val extension = PolyworldGithubReleaseExtension.create(project) + +githubRelease { + dryRun(extension.dryRun) + token(extension.token) + owner(extension.owner) + releaseName { version.toString() } + tagName { version.toString() } + generateReleaseNotes { true } +} diff --git a/conventions/src/main/kotlin/com/github/kyhule/polyworld/build/PolyworldGithubReleaseExtension.kt b/conventions/src/main/kotlin/com/github/kyhule/polyworld/build/PolyworldGithubReleaseExtension.kt new file mode 100644 index 0000000..81bba63 --- /dev/null +++ b/conventions/src/main/kotlin/com/github/kyhule/polyworld/build/PolyworldGithubReleaseExtension.kt @@ -0,0 +1,22 @@ +package com.github.kyhule.polyworld.build + +import org.gradle.api.Project +import org.gradle.api.model.ObjectFactory +import org.gradle.api.provider.Property +import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.property +import javax.inject.Inject + +open class PolyworldGithubReleaseExtension @Inject constructor( + objects: ObjectFactory +) { + val dryRun: Property = objects.property().convention(false) + val owner: Property = objects.property().convention("kyhule") + val token: Property = objects.property().convention(System.getenv("GITHUB_TOKEN")) + + companion object { + const val name = "polyworldGithubRelease" + + internal fun create(project: Project): PolyworldGithubReleaseExtension = project.extensions.create(name) + } +} diff --git a/plugin/src/functionalTest/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPluginFunctionalTest.kt b/plugin/src/functionalTest/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPluginFunctionalTest.kt new file mode 100644 index 0000000..337909f --- /dev/null +++ b/plugin/src/functionalTest/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPluginFunctionalTest.kt @@ -0,0 +1,43 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package com.github.kyhule.polyworld.build + +import java.io.File +import kotlin.test.assertTrue +import kotlin.test.Test +import org.gradle.testkit.runner.GradleRunner +import org.junit.jupiter.api.io.TempDir + +/** + * A simple functional test for the 'com.github.kyhule.polyworld.build.greeting' plugin. + */ +class PolyworldGradlePluginPluginFunctionalTest { + + @field:TempDir + lateinit var projectDir: File + + private val buildFile by lazy { projectDir.resolve("build.gradle") } + private val settingsFile by lazy { projectDir.resolve("settings.gradle") } + + @Test fun `can run task`() { + // Set up the test build + settingsFile.writeText("") + buildFile.writeText(""" + plugins { + id('com.github.kyhule.polyworld.build.greeting') + } + """.trimIndent()) + + // Run the build + val runner = GradleRunner.create() + runner.forwardOutput() + runner.withPluginClasspath() + runner.withArguments("greeting") + runner.withProjectDir(projectDir) + val result = runner.build() + + // Verify the result + assertTrue(result.output.contains("Hello from plugin 'com.github.kyhule.polyworld.build.greeting'")) + } +} diff --git a/plugin/src/main/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPlugin.kt b/plugin/src/main/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPlugin.kt new file mode 100644 index 0000000..537bf62 --- /dev/null +++ b/plugin/src/main/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPlugin.kt @@ -0,0 +1,21 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package com.github.kyhule.polyworld.build + +import org.gradle.api.Project +import org.gradle.api.Plugin + +/** + * A simple 'hello world' plugin. + */ +class PolyworldGradlePluginPlugin: Plugin { + override fun apply(project: Project) { + // Register a task + project.tasks.register("greeting") { task -> + task.doLast { + println("Hello from plugin 'com.github.kyhule.polyworld.build.greeting'") + } + } + } +} diff --git a/plugin/src/test/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPluginTest.kt b/plugin/src/test/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPluginTest.kt new file mode 100644 index 0000000..7bede58 --- /dev/null +++ b/plugin/src/test/kotlin/com/github/kyhule/polyworld/build/PolyworldGradlePluginPluginTest.kt @@ -0,0 +1,22 @@ +/* + * This Kotlin source file was generated by the Gradle 'init' task. + */ +package com.github.kyhule.polyworld.build + +import org.gradle.testfixtures.ProjectBuilder +import kotlin.test.Test +import kotlin.test.assertNotNull + +/** + * A simple unit test for the 'com.github.kyhule.polyworld.build.greeting' plugin. + */ +class PolyworldGradlePluginPluginTest { + @Test fun `plugin registers task`() { + // Create a test project and apply the plugin + val project = ProjectBuilder.builder().build() + project.plugins.apply("com.github.kyhule.polyworld.build.greeting") + + // Verify the result + assertNotNull(project.tasks.findByName("greeting")) + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 8d9dbe6..f6d81d8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,5 @@ rootProject.name = "polyworld-gradle-plugin" include("conventions") -include("plugin") pluginManagement { repositories {