From 259e7f40fbe98baa7d0b4ebc9dbe86aa87f38713 Mon Sep 17 00:00:00 2001 From: andresmr Date: Tue, 7 May 2024 13:43:22 +0200 Subject: [PATCH 1/9] [ANDROAPP-6157] Maven release --- .github/workflows/continuous-deployment.yml | 5 +- .github/workflows/scripts/publish-maven.sh | 9 ++ build.gradle.kts | 13 +++ convention-plugins/build.gradle.kts | 5 + convention-plugins/src/main/kotlin/Props.kt | 15 +++ .../kotlin/convention.publication.gradle.kts | 92 ++++++------------- designsystem/build.gradle.kts | 8 ++ 7 files changed, 82 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/scripts/publish-maven.sh create mode 100644 convention-plugins/src/main/kotlin/Props.kt diff --git a/.github/workflows/continuous-deployment.yml b/.github/workflows/continuous-deployment.yml index 0a95b8068..958482e7f 100644 --- a/.github/workflows/continuous-deployment.yml +++ b/.github/workflows/continuous-deployment.yml @@ -6,7 +6,6 @@ name: Continuous deployment on: push: branches: - - main - develop # Allows you to run this workflow manually from the Actions tab @@ -36,7 +35,9 @@ jobs: # Create publish to maven - name: Publish to maven - run: ./gradlew publishAllPublicationsToSonatypeRepository + run: ./.github/workflows/scripts/publish-maven.sh env: OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_PRIVATE_KEY: ${{ secrets.PGP_PRIVATE_KEY }} + SIGNING_PASSWORD: ${{ secrets.PGP_PASSPHRASE }} diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh new file mode 100644 index 000000000..d15403310 --- /dev/null +++ b/.github/workflows/scripts/publish-maven.sh @@ -0,0 +1,9 @@ +set -x + +branch=$(git rev-parse --abbrev-ref HEAD) + +if [ "$branch" = "main" ]; then + ./gradlew :designSystem:publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix +else then + ./gradlew :designSystem:publishToSonatype +fi \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index b79495698..26f34cecc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,6 +8,7 @@ plugins { id("org.jetbrains.compose") apply false id("org.jlleitschuh.gradle.ktlint") version "11.5.1" id("org.jetbrains.dokka") version "1.9.20" + id("io.github.gradle-nexus.publish-plugin") version "1.3.0" } allprojects { @@ -67,3 +68,15 @@ subprojects { } } } + +val ossrhUsername: String? = System.getenv("OSSRH_USERNAME") +val ossrhPassword: String? = System.getenv("OSSRH_PASSWORD") + +nexusPublishing { + this.repositories { + sonatype { + username.set(ossrhUsername) + password.set(ossrhPassword) + } + } +} diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts index 39bd51e4f..d922e23bb 100644 --- a/convention-plugins/build.gradle.kts +++ b/convention-plugins/build.gradle.kts @@ -3,5 +3,10 @@ plugins { } repositories { + mavenCentral() gradlePluginPortal() // To use 'maven-publish' and 'signing' plugins in our own plugin +} + +dependencies { + implementation("io.github.gradle-nexus:publish-plugin:1.3.0") } \ No newline at end of file diff --git a/convention-plugins/src/main/kotlin/Props.kt b/convention-plugins/src/main/kotlin/Props.kt new file mode 100644 index 000000000..a1f5e19ad --- /dev/null +++ b/convention-plugins/src/main/kotlin/Props.kt @@ -0,0 +1,15 @@ +object Props { + const val DESCRIPTION = "Compose Multiplatform DHIS2 Mobile UI components library" + + const val REPOSITORY_SYSTEM = "GitHub" + const val REPOSITORY_URL = "https://github.com/dhis2/dhis2-mobile-ui" + + const val AUTHOR_NAME = "Mobile team" + const val AUTHOR_EMAIL = "android@dhis2.org" + + const val ORGANIZATION_NAME = "UiO" + const val ORGANIZATION_URL = "http://www.dhis2.org" + + const val LICENSE_NAME = "BSD-3-Clause" + const val LICENSE_URL = "https://opensource.org/license/bsd-3-clause/" +} \ No newline at end of file diff --git a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts index d7f2bd055..05975963a 100644 --- a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts +++ b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts @@ -1,101 +1,67 @@ -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 +val ossrhUsername: String? = System.getenv("OSSRH_USERNAME") +val ossrhPassword: String? = System.getenv("OSSRH_PASSWORD") +val signingPrivateKey: String? = System.getenv("SIGNING_PRIVATE_KEY") +val signingPassword: String? = System.getenv("SIGNING_PASSWORD") -// 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("SIGNING_KEY_ID") - ext["signing.password"] = System.getenv("SIGNING_PASSWORD") - ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE") - ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME") - ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") -} +val dokkaHtml = tasks.findByName("dokkaHtml")!! -val javadocJar by tasks.registering(Jar::class) { +val dokkaHtmlJar = tasks.register("dokkaHtmlJar") { + dependsOn(dokkaHtml) + from(dokkaHtml.outputs) archiveClassifier.set("javadoc") } -fun getExtraString(name: String) = ext[name]?.toString() - publishing { - // Configure maven central repository - repositories { - maven { - name = "sonatype" - setUrl("https://oss.sonatype.org/content/repositories/snapshots/") - credentials { - username = getExtraString("ossrhUsername") - password = getExtraString("ossrhPassword") - } - } - } // Configure all publications publications.withType { - // Stub javadoc.jar artifact - artifact(javadocJar.get()) + artifact(dokkaHtmlJar) // Provide artifacts information requited by Maven Central pom { name.set("DHIS2 Mobile Design system") - description.set("Compose Multiplatform DHIS2 Mobile UI components library") - url.set("https://github.com/dhis2/dhis2-mobile-ui") + description.set(Props.DESCRIPTION) + url.set(Props.REPOSITORY_URL) licenses { license { - name.set("MIT") - url.set("https://opensource.org/licenses/MIT") + name.set(Props.LICENSE_NAME) + url.set(Props.LICENSE_URL) } } + organization { + name.set(Props.ORGANIZATION_NAME) + url.set(Props.ORGANIZATION_URL) + } developers { developer { - id.set("andresmr") - name.set("Andres") - email.set("andres@dhis2.org") - } - developer { - id.set("xavimolloy") - name.set("Xavi") - email.set("xavi@dhis2.org") - } - developer { - id.set("DavidAparicioAlbaAsenjo") - name.set("David") - email.set("david.aparicio@dhis2.org") + name.set(Props.AUTHOR_NAME) + email.set(Props.AUTHOR_EMAIL) + organization.set(Props.ORGANIZATION_NAME) + organizationUrl.set(Props.ORGANIZATION_URL) } } scm { url.set("https://github.com/dhis2/dhis2-mobile-ui") } + issueManagement { + system.set(Props.REPOSITORY_SYSTEM) + url.set(Props.REPOSITORY_URL) + } } } } // Signing artifacts. Signing.* extra properties values will be used signing { - isRequired = false + println("Version: $version") + println("SigningPrivateKey: $signingPrivateKey") + setRequired({ !version.toString().endsWith("-SNAPSHOT") }) + useInMemoryPgpKeys(signingPrivateKey, signingPassword) sign(publishing.publications) } \ No newline at end of file diff --git a/designsystem/build.gradle.kts b/designsystem/build.gradle.kts index ef65fbd7e..d9b063334 100644 --- a/designsystem/build.gradle.kts +++ b/designsystem/build.gradle.kts @@ -9,6 +9,14 @@ plugins { id("app.cash.paparazzi").version("1.3.3") } +/** + * Property from the Gradle command line. To remove the snapshot suffix from the version. + */ +if (project.hasProperty("removeSnapshotSuffix")) { + val mainVersion = (version as String).split("-SNAPSHOT")[0] + version = mainVersion +} + kotlin { androidTarget { publishLibraryVariants("release") From ee845272d62d5e0f73500283a2178920ea2917d1 Mon Sep 17 00:00:00 2001 From: andresmr Date: Wed, 8 May 2024 10:16:05 +0200 Subject: [PATCH 2/9] [ANDROAPP-6157] remove unused repositories and dependencies --- convention-plugins/build.gradle.kts | 5 ----- .../src/main/kotlin/convention.publication.gradle.kts | 2 -- 2 files changed, 7 deletions(-) diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts index d922e23bb..ef06b2bcf 100644 --- a/convention-plugins/build.gradle.kts +++ b/convention-plugins/build.gradle.kts @@ -3,10 +3,5 @@ plugins { } repositories { - mavenCentral() gradlePluginPortal() // To use 'maven-publish' and 'signing' plugins in our own plugin } - -dependencies { - implementation("io.github.gradle-nexus:publish-plugin:1.3.0") -} \ No newline at end of file diff --git a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts index 05975963a..207abec3d 100644 --- a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts +++ b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts @@ -59,8 +59,6 @@ publishing { // Signing artifacts. Signing.* extra properties values will be used signing { - println("Version: $version") - println("SigningPrivateKey: $signingPrivateKey") setRequired({ !version.toString().endsWith("-SNAPSHOT") }) useInMemoryPgpKeys(signingPrivateKey, signingPassword) sign(publishing.publications) From 35e73db1eac4cbb3106387bb130e15e1b9eb5a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Garc=C3=ADa?= Date: Wed, 8 May 2024 11:54:49 +0200 Subject: [PATCH 3/9] Make maven-publish script executable (#238) --- .github/workflows/scripts/publish-maven.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .github/workflows/scripts/publish-maven.sh diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh old mode 100644 new mode 100755 From be82822fc4939b58174ad4531dd76492b6ea49d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Miguel=20Rubio?= Date: Wed, 8 May 2024 11:59:58 +0200 Subject: [PATCH 4/9] remove then (#239) --- .github/workflows/scripts/publish-maven.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh index d15403310..a6df42989 100755 --- a/.github/workflows/scripts/publish-maven.sh +++ b/.github/workflows/scripts/publish-maven.sh @@ -4,6 +4,6 @@ branch=$(git rev-parse --abbrev-ref HEAD) if [ "$branch" = "main" ]; then ./gradlew :designSystem:publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix -else then +else ./gradlew :designSystem:publishToSonatype fi \ No newline at end of file From 5164f5b66bb21d8740e8addd768514ce132ed2b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Miguel=20Rubio?= Date: Wed, 8 May 2024 12:24:30 +0200 Subject: [PATCH 5/9] add project dir for all maven tasks (#240) --- .github/workflows/scripts/publish-maven.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh index a6df42989..8015606f1 100755 --- a/.github/workflows/scripts/publish-maven.sh +++ b/.github/workflows/scripts/publish-maven.sh @@ -3,7 +3,7 @@ set -x branch=$(git rev-parse --abbrev-ref HEAD) if [ "$branch" = "main" ]; then - ./gradlew :designSystem:publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix + ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix --project-dir designSystem else - ./gradlew :designSystem:publishToSonatype + ./gradlew publishToSonatype --project-dir designSystem fi \ No newline at end of file From 640ada731d45ac82085b5dd97055d7d9ddb7dcc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Miguel=20Rubio?= Date: Wed, 8 May 2024 12:29:06 +0200 Subject: [PATCH 6/9] remove camelcase (#241) --- .github/workflows/scripts/publish-maven.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh index 8015606f1..116db13b3 100755 --- a/.github/workflows/scripts/publish-maven.sh +++ b/.github/workflows/scripts/publish-maven.sh @@ -3,7 +3,7 @@ set -x branch=$(git rev-parse --abbrev-ref HEAD) if [ "$branch" = "main" ]; then - ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix --project-dir designSystem + ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix --project-dir designsystem else - ./gradlew publishToSonatype --project-dir designSystem + ./gradlew publishToSonatype --project-dir designsystem fi \ No newline at end of file From a3651e590cd58f2a3d48d70fc798be1b48c1581b Mon Sep 17 00:00:00 2001 From: andresmr Date: Wed, 8 May 2024 12:41:36 +0200 Subject: [PATCH 7/9] remove closeAndReleaseSonatypeStagingRepository --- .github/workflows/scripts/publish-maven.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh index 116db13b3..c041150c8 100755 --- a/.github/workflows/scripts/publish-maven.sh +++ b/.github/workflows/scripts/publish-maven.sh @@ -3,7 +3,7 @@ set -x branch=$(git rev-parse --abbrev-ref HEAD) if [ "$branch" = "main" ]; then - ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix --project-dir designsystem + ./gradlew :designsystem:publishToSonatype -PremoveSnapshotSuffix else - ./gradlew publishToSonatype --project-dir designsystem + ./gradlew :designsystem:publishToSonatype fi \ No newline at end of file From 661735f467c693c1e8cc4abc6b10226772da3e62 Mon Sep 17 00:00:00 2001 From: andresmr Date: Wed, 8 May 2024 12:48:42 +0200 Subject: [PATCH 8/9] remove designsystem prefix --- .github/workflows/scripts/publish-maven.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh index c041150c8..f1b1a1de5 100755 --- a/.github/workflows/scripts/publish-maven.sh +++ b/.github/workflows/scripts/publish-maven.sh @@ -3,7 +3,7 @@ set -x branch=$(git rev-parse --abbrev-ref HEAD) if [ "$branch" = "main" ]; then - ./gradlew :designsystem:publishToSonatype -PremoveSnapshotSuffix + ./gradlew publishToSonatype -PremoveSnapshotSuffix else - ./gradlew :designsystem:publishToSonatype + ./gradlew publishToSonatype fi \ No newline at end of file From 619f4430c31d7825ddbadba5669262a958302cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Miguel=20Rubio?= Date: Wed, 8 May 2024 13:30:03 +0200 Subject: [PATCH 9/9] fix maven (#242) * move group * add sign fix * add group to designsystem * add closeAndReleaseSonatypeStagingRepository --- .github/workflows/scripts/publish-maven.sh | 4 ++-- build.gradle.kts | 2 ++ .../src/main/kotlin/convention.publication.gradle.kts | 9 ++++++++- designsystem/build.gradle.kts | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/scripts/publish-maven.sh b/.github/workflows/scripts/publish-maven.sh index f1b1a1de5..c50f11238 100755 --- a/.github/workflows/scripts/publish-maven.sh +++ b/.github/workflows/scripts/publish-maven.sh @@ -3,7 +3,7 @@ set -x branch=$(git rev-parse --abbrev-ref HEAD) if [ "$branch" = "main" ]; then - ./gradlew publishToSonatype -PremoveSnapshotSuffix + ./gradlew :designsystem:publishToSonatype closeAndReleaseSonatypeStagingRepository -PremoveSnapshotSuffix else - ./gradlew publishToSonatype + ./gradlew :designsystem:publishToSonatype fi \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 26f34cecc..13edc4c64 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +group = "org.hisp.dhis.mobile" + plugins { kotlin("multiplatform") apply false id("com.android.application") apply false diff --git a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts index 207abec3d..3c6ff87c8 100644 --- a/convention-plugins/src/main/kotlin/convention.publication.gradle.kts +++ b/convention-plugins/src/main/kotlin/convention.publication.gradle.kts @@ -62,4 +62,11 @@ signing { setRequired({ !version.toString().endsWith("-SNAPSHOT") }) useInMemoryPgpKeys(signingPrivateKey, signingPassword) sign(publishing.publications) -} \ No newline at end of file +} + +// Fix Gradle warning about signing tasks using publishing task outputs without explicit dependencies +// https://github.com/gradle/gradle/issues/26091 +tasks.withType().configureEach { + val signingTasks = tasks.withType() + mustRunAfter(signingTasks) +} diff --git a/designsystem/build.gradle.kts b/designsystem/build.gradle.kts index d9b063334..43d36ceac 100644 --- a/designsystem/build.gradle.kts +++ b/designsystem/build.gradle.kts @@ -1,5 +1,5 @@ -group = "org.hisp.dhis.mobile" version = "0.2-SNAPSHOT" +group = "org.hisp.dhis.mobile" plugins { kotlin("multiplatform")