Skip to content

Commit

Permalink
Creates github release convention (#13)
Browse files Browse the repository at this point in the history
* Creates github release convention

* Fixes apiEndpoint
  • Loading branch information
kyhule authored Jun 9, 2023
1 parent cdd4be7 commit 764e07f
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 1 deletion.
3 changes: 3 additions & 0 deletions conventions/src/main/kotlin/PluginAccessors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
@@ -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 }
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> = objects.property<Boolean>().convention(false)
val owner: Property<CharSequence> = objects.property<CharSequence>().convention("kyhule")
val token: Property<CharSequence> = objects.property<CharSequence>().convention(System.getenv("GITHUB_TOKEN"))

companion object {
const val name = "polyworldGithubRelease"

internal fun create(project: Project): PolyworldGithubReleaseExtension = project.extensions.create(name)
}
}
Original file line number Diff line number Diff line change
@@ -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'"))
}
}
Original file line number Diff line number Diff line change
@@ -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<Project> {
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'")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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"))
}
}
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
rootProject.name = "polyworld-gradle-plugin"
include("conventions")
include("plugin")

pluginManagement {
repositories {
Expand Down

0 comments on commit 764e07f

Please sign in to comment.