From e6eec8eab22321e101b6d20b1b18e0a520b12ec3 Mon Sep 17 00:00:00 2001 From: Paulo Pinheiro Date: Wed, 28 Jun 2023 12:53:58 -0300 Subject: [PATCH] [Kotlin] Add workflow to release kotlin multiplatform version --- .github/workflows/release.yml | 26 +++++ kotlin/convention-plugins/build.gradle.kts | 7 ++ .../kotlin/convention.publication.gradle.kts | 95 +++++++++++++++++++ kotlin/flatbuffers-kotlin/build.gradle.kts | 1 + kotlin/settings.gradle.kts | 1 + 5 files changed, 130 insertions(+) create mode 100644 kotlin/convention-plugins/build.gradle.kts create mode 100644 kotlin/convention-plugins/src/main/kotlin/convention.publication.gradle.kts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e087d6f67a1..a6ff0268996 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -100,6 +100,32 @@ jobs: OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }} MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} + + publish-maven-kotlin: + name: Publish Maven - Kotlin + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./kotlin + steps: + - uses: actions/checkout@v3 + - name: Set up Maven Central Repository + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + cache: 'maven' + server-id: ossrh + server-username: OSSRH_USERNAME + server-password: OSSRH_PASSWORD + gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE # this needs to be an env var + - name: Publish Kotlin Library on Maven + run: ./gradlew publishAllPublicationsToSonatypeRepository + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} diff --git a/kotlin/convention-plugins/build.gradle.kts b/kotlin/convention-plugins/build.gradle.kts new file mode 100644 index 00000000000..52b9cc0a8c6 --- /dev/null +++ b/kotlin/convention-plugins/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() +} diff --git a/kotlin/convention-plugins/src/main/kotlin/convention.publication.gradle.kts b/kotlin/convention-plugins/src/main/kotlin/convention.publication.gradle.kts new file mode 100644 index 00000000000..e526279654b --- /dev/null +++ b/kotlin/convention-plugins/src/main/kotlin/convention.publication.gradle.kts @@ -0,0 +1,95 @@ +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.tasks.bundling.Jar +import org.gradle.kotlin.dsl.`maven-publish` +import org.gradle.kotlin.dsl.signing +import java.util.* + +plugins { + `maven-publish` + signing +} + +// Stub secrets to let the project sync and build without the publication values set up +ext["signing.keyId"] = null +ext["signing.password"] = null +ext["signing.secretKeyRingFile"] = null +ext["ossrhUsername"] = null +ext["ossrhPassword"] = null + +// Grabbing secrets from local.properties file or from environment variables, which could be used on CI +val secretPropsFile = project.rootProject.file("local.properties") +if (secretPropsFile.exists()) { + secretPropsFile.reader().use { + Properties().apply { + load(it) + } + }.onEach { (name, value) -> + ext[name.toString()] = value + } +} else { + ext["signing.keyId"] = System.getenv("OSSRH_USERNAME") + ext["signing.password"] = System.getenv("OSSRH_PASSWORD") + ext["signing.secretKeyRingFile"] = System.getenv("INPUT_GPG_PRIVATE_KEY") + ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME") + ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") +} + +val javadocJar by tasks.registering(Jar::class) { + archiveClassifier.set("javadoc") +} + +fun getExtraString(name: String) = ext[name]?.toString() + +publishing { + // Configure maven central repository + repositories { + maven { + name = "sonatype" + setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = getExtraString("ossrhUsername") + password = getExtraString("ossrhPassword") + } + } + } + + // Configure all publications + publications.withType { + // Stub javadoc.jar artifact + artifact(javadocJar.get()) + + // Provide artifacts information requited by Maven Central + pom { + name.set("Flatbuffers Kotlin") + description.set("Memory Efficient Serialization Library") + url.set("https://github.com/google/flatbuffers") + + licenses { + license { + name.set("Apache License V2.0") + url.set("https://raw.githubusercontent.com/google/flatbuffers/master/LICENSE") + } + } + developers { + developer { + id.set("https://github.com/paulovap") + name.set("Paulo Pinheiro") + email.set("paulovictor.pinheiro@gmail.com") + } + developer { + id.set("https://github.com/dbaileychess") + name.set("Derek Bailey") + email.set("dbaileychess@gmail.com") + } + } + scm { + url.set("https://github.com/google/flatbuffers") + } + } + } +} + +// Signing artifacts. Signing.* extra properties values will be used +signing { + sign(publishing.publications) +} diff --git a/kotlin/flatbuffers-kotlin/build.gradle.kts b/kotlin/flatbuffers-kotlin/build.gradle.kts index d4086537217..1b8d2242dbd 100644 --- a/kotlin/flatbuffers-kotlin/build.gradle.kts +++ b/kotlin/flatbuffers-kotlin/build.gradle.kts @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkConfig plugins { kotlin("multiplatform") + id("convention.publication") } diff --git a/kotlin/settings.gradle.kts b/kotlin/settings.gradle.kts index 0fd19c4d22d..9b6981eebe0 100644 --- a/kotlin/settings.gradle.kts +++ b/kotlin/settings.gradle.kts @@ -1,3 +1,4 @@ rootProject.name = "flatbuffers-kotlin" +includeBuild("convention-plugins") include("flatbuffers-kotlin") include("benchmark")