From af4d9e2c97710054be5ec2d1b1a3b05f8c4d8f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Thu, 18 Jul 2024 11:44:44 +0200 Subject: [PATCH] chore: publish artifact to maven configuration (#28) --- .github/workflows/release.yml | 32 +++++++ build.gradle.kts | 17 +++- settings.gradle.kts | 1 - unleashandroidsdk/build.gradle.kts | 92 ++++++++++++++++++- unleashandroidsdk/proguard-rules.pro | 4 +- .../getunleash/android/DefaultUnleashTest.kt | 2 +- 6 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..835f98e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Publish SDK + +on: + push: + tags: + - 'v*' + +jobs: + deploy-release: + runs-on: ubuntu-22.04 + if: startsWith(github.ref, 'refs/tags') + steps: + - uses: actions/checkout@v4 + name: Checkout code + - uses: burrunan/gradle-cache-action@v1 + name: Deploy Release + env: + ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }} + ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }} + ORG_GRADLE_PROJECT_signingPassphrase: ${{ secrets.GPG_PASSPHRASE }} + with: + job-id: release + arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository + - name: Create release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + prerelease: ${{ contains(github.ref, 'beta') || contains(github.ref, 'alpha') }} diff --git a/build.gradle.kts b/build.gradle.kts index e3f8a07..9f5ddda 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,4 +3,19 @@ plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.jetbrains.kotlin.android) apply false alias(libs.plugins.android.library) apply false -} \ No newline at end of file + id("io.github.gradle-nexus.publish-plugin") version "1.1.0" +} + +val sonatypeUsername: String? by project +val sonatypePassword: String? by project + +nexusPublishing { + repositories { + sonatype { + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + username.set(sonatypeUsername) + password.set(sonatypePassword) + } + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 7a31de8..ec1b1b1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -12,7 +12,6 @@ pluginManagement { } } dependencyResolutionManagement { - repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() diff --git a/unleashandroidsdk/build.gradle.kts b/unleashandroidsdk/build.gradle.kts index e2253a3..a7a3c78 100644 --- a/unleashandroidsdk/build.gradle.kts +++ b/unleashandroidsdk/build.gradle.kts @@ -1,8 +1,15 @@ plugins { + `maven-publish` + signing alias(libs.plugins.android.library) alias(libs.plugins.jetbrains.kotlin.android) + id("org.jetbrains.dokka") version "1.7.10" + id("pl.allegro.tech.build.axion-release") version "1.13.6" } +val tagVersion = System.getenv("GITHUB_REF")?.split('/')?.last() +project.version = scmVersion.version + android { namespace = "io.getunleash.android" compileSdk = 34 @@ -10,11 +17,17 @@ android { defaultConfig { minSdk = 21 + aarMetadata { + minCompileSdk = 29 + } testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") + consumerProguardFiles("proguard-rules.pro") } buildTypes { + debug { + + } release { isMinifyEnabled = false proguardFiles( @@ -30,6 +43,14 @@ android { kotlinOptions { jvmTarget = "1.8" } + + publishing { + multipleVariants { + includeBuildTypeValues("debug", "release") + allVariants() + withJavadocJar() + } + } } dependencies { @@ -37,11 +58,11 @@ dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) implementation(libs.androidx.work.ktx) + implementation(libs.androidx.lifecycle.process) implementation(libs.jackson.databind) implementation(libs.jackson.core) implementation(libs.jackson.module.kotlin) implementation(libs.jackson.datatype.jsr310) - implementation(libs.androidx.lifecycle.process) api(libs.okhttp) testImplementation(libs.junit) @@ -58,4 +79,69 @@ dependencies { androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) androidTestImplementation(libs.okhttp.mockserver) -} \ No newline at end of file +} + +publishing { + repositories { + repositories { + maven { + url = uri(layout.buildDirectory.dir("repo")) + name = "test" + } + } + mavenLocal() + } + + publications { + afterEvaluate { + create("mavenJava") { + from(components["release"]) + groupId = "io.getunleash" + artifactId = "unleash-android" + version = version + pom { + name.set("Unleash Android") + description.set("Android SDK for Unleash") + url.set("https://gh.getunleash.io/unleash-android") + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + id.set("gastonfournier") + name.set("Gastón Fournier") + email.set("gaston@getunleash.io") + } + developer { + id.set("chrkolst") + name.set("Christopher Kolstad") + email.set("chriswk@getunleash.io") + } + developer { + id.set("ivarconr") + name.set("Ivar Conradi Østhus") + email.set("ivarconr@getunleash.io") + } + } + scm { + connection.set("scm:git:https://github.com/Unleash/unleash-android") + developerConnection.set("scm:git:ssh://git@github.com:Unleash/unleash-android") + url.set("https://github.com/Unleash/unleash-android") + } + } + } + } + } +} + +val signingKey: String? by project +val signingPassphrase: String? by project +signing { + if (signingKey != null && signingPassphrase != null) { + useInMemoryPgpKeys(signingKey, signingPassphrase) + sign(publishing.publications["mavenJava"]) + } +} diff --git a/unleashandroidsdk/proguard-rules.pro b/unleashandroidsdk/proguard-rules.pro index 481bb43..de8dcf2 100644 --- a/unleashandroidsdk/proguard-rules.pro +++ b/unleashandroidsdk/proguard-rules.pro @@ -18,4 +18,6 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file +#-renamesourcefileattribute SourceFile +-keep public class io.getunleash.** { *; } +-keep class com.fasterxml.** { *; } diff --git a/unleashandroidsdk/src/test/java/io/getunleash/android/DefaultUnleashTest.kt b/unleashandroidsdk/src/test/java/io/getunleash/android/DefaultUnleashTest.kt index f548744..e04b078 100644 --- a/unleashandroidsdk/src/test/java/io/getunleash/android/DefaultUnleashTest.kt +++ b/unleashandroidsdk/src/test/java/io/getunleash/android/DefaultUnleashTest.kt @@ -219,7 +219,7 @@ class DefaultUnleashTest: BaseTest() { }) unleash.start() - await().atMost(1, TimeUnit.SECONDS).until { ready } + await().atMost(2, TimeUnit.SECONDS).until { ready } val variant = unleash.getVariant("AwesomeDemo") assertThat(variant).isNotNull assertThat(variant.enabled).isTrue()