Skip to content

Commit

Permalink
ci: Deploying to Maven central (#50)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicklas Lundin <[email protected]>
  • Loading branch information
nicklasl authored Oct 12, 2023
1 parent c66558a commit 9629007
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 41 deletions.
42 changes: 26 additions & 16 deletions .github/workflows/release_please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ jobs:
run: |
echo "$RELEASE_PLEASE_OUTPUT"
# Outputs are namespaced by package when using a manifest in Release Please
outputs:
release_created: ${{ steps.release.outputs['OpenFeature--release_created'] }}
# Version doesn't include `v` as a prefix. This is undocumented
version: ${{ steps.release.outputs['OpenFeature--version'] }}
upload_url: ${{ steps.release.outputs['OpenFeature--upload_url'] }}
release_created: ${{ steps.release.outputs.release_created }}

kotlin-release:
needs: release-please
Expand All @@ -49,23 +45,37 @@ jobs:
- uses: actions/checkout@v4

- name: Configure GPG Key
run: |
echo -n "$GPG_SIGNING_KEY" | gpg --import
gpg --pinentry-mode=loopback --export-secret-key 08C5EC5C > ~/.gnupg/secring.gpg
env:
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}

- name: Add signing secrets to gradle.properties
run: |
mkdir -p ~/.gradle/
echo "signing.keyId=08C5EC5C" >> ~/.gradle/gradle.properties
echo "signing.secretKeyRingFile=/home/runner/.gnupg/secring.gpg" >> ~/.gradle/gradle.properties
echo "signing.password=$GPG_SIGNING_KEY_PASSWORD" >> ~/.gradle/gradle.properties
env:
GPG_SIGNING_KEY_ID: ${{ secrets.GPG_SIGNING_KEY_ID }}
GPG_SIGNING_KEY_PASSWORD: ${{ secrets.GPG_SIGNING_KEY_PASSWORD }}

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'zulu'

- name: Grant Permission for Gradlew to Execute
run: chmod +x gradlew

- name: Build AAR ⚙️🛠
run: bash ./gradlew :openfeature:assemble

- name: Upload Openfeature SDK AAR 🗳
uses: actions/upload-release-asset@v1
- name: Publish to Sonatype
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release-please.outputs.upload_url }}
asset_path: OpenFeature/build/outputs/aar/OpenFeature-release.aar
asset_name: openfeature-sdk.aar
asset_content_type: application/aar
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
run: ./gradlew publishToSonatype closeSonatypeStagingRepository --no-daemon --stacktrace

- name: Clean up signing secrets
run: rm ~/.gradle/gradle.properties
92 changes: 67 additions & 25 deletions OpenFeature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("maven-publish")
id("signing")
id("org.jlleitschuh.gradle.ktlint")
kotlin("plugin.serialization") version "1.9.10"
}
Expand Down Expand Up @@ -38,41 +39,82 @@ android {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
}

afterEvaluate {
publishing {
publications {
register<MavenPublication>("release") {
groupId = "dev.openfeature"
artifactId = "kotlin-sdk"
version = releaseVersion
singleVariant("release") {
withJavadocJar()
withSourcesJar()
}
}
}

from(components["release"])
artifact(androidSourcesJar.get())
publishing {
publications {
register<MavenPublication>("release") {
groupId = "dev.openfeature"
artifactId = "kotlin-sdk"
version = releaseVersion

pom {
name.set("OpenfeatureSDK")
pom {
name.set("OpenFeature Android SDK")
description.set(
"This is the Android implementation of OpenFeature, a vendor-agnostic abstraction library for evaluating feature flags."
)
url.set("https://openfeature.dev")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("vahidlazio")
name.set("Vahid Torkaman")
email.set("[email protected]")
}
developer {
id.set("fabriziodemaria")
name.set("Fabrizio Demaria")
email.set("[email protected]")
}
developer {
id.set("nicklasl")
name.set("Nicklas Lundin")
email.set("[email protected]")
}
developer {
id.set("nickybondarenko")
name.set("Nicky Bondarenko")
email.set("[email protected]")
}
}
scm {
connection.set(
"scm:git:https://github.com/open-feature/kotlin-sdk.git"
)
developerConnection.set(
"scm:git:ssh://open-feature/kotlin-sdk.git"
)
url.set("https://github.com/open-feature/kotlin-sdk")
}
}

afterEvaluate {
from(components["release"])
}
}
}
}

val androidSourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(android.sourceSets.getByName("main").java.srcDirs)
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
testImplementation("junit:junit:4.13.2")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
}

// Assembling should be performed before publishing package
tasks.named("publish") {
dependsOn("assemble")
signing {
sign(publishing.publications["release"])
}
12 changes: 12 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@ plugins {
id("com.android.library").version("7.4.2").apply(false)
id("org.jetbrains.kotlin.android").version("1.9.10").apply(false)
id("org.jlleitschuh.gradle.ktlint").version("11.6.1").apply(true)
id("io.github.gradle-nexus.publish-plugin").version("1.3.0").apply(true)
}

nexusPublishing {
this.repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_PASSWORD")
}
}
}

0 comments on commit 9629007

Please sign in to comment.