From 361952d7e85e3ec782068a02bc9f9cee6e18f5d3 Mon Sep 17 00:00:00 2001 From: overpas Date: Sun, 27 Oct 2024 20:12:57 +0400 Subject: [PATCH] Update publishing configuration to support the new maven publication process --- .github/workflows/publish.yml | 55 +++++---- README.md | 6 +- convention-plugins/build.gradle.kts | 1 + .../src/main/kotlin/publication.gradle.kts | 106 ------------------ .../src/main/kotlin/publish.gradle.kts | 50 +++++++++ gradle.properties | 6 +- gradle/libs.versions.toml | 3 + treemap-chart-compose/build.gradle.kts | 4 +- treemap-chart/build.gradle.kts | 2 +- 9 files changed, 97 insertions(+), 136 deletions(-) delete mode 100644 convention-plugins/src/main/kotlin/publication.gradle.kts create mode 100644 convention-plugins/src/main/kotlin/publish.gradle.kts diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a4274ee..5b16f03 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,31 +6,44 @@ on: jobs: publish: - name: Release build and publish - runs-on: ubuntu-latest + name: Publish + runs-on: macos-latest steps: - - name: Check out code - uses: actions/checkout@v4 - - name: Set up JDK 17 - uses: actions/setup-java@v4 + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 with: - distribution: zulu - java-version: 17 + distribution: 'zulu' + java-version: '17' - # Builds the release artifacts of the library - - name: Release build - run: ./gradlew build + - name: Install GPG + env: + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + run: | + brew install gpg + echo "$SIGNING_KEY" | gpg --dearmor > ${HOME}/secring.gpg - # Generates other artifacts - - name: Source jar - run: ./gradlew androidReleaseSourcesJar javadocJar + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 - # Runs upload, and then closes & releases the repository - - name: Publish to MavenCentral - run: ./gradlew publishAllPublicationsToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository + - name: Add Gradle Properties env: - OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} - OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + MAVEN_CENTRAL_USER_NAME: ${{ secrets.MAVEN_CENTRAL_USER_NAME }} + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} - SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} - SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} + run: | + echo "mavenCentralUsername=${MAVEN_CENTRAL_USER_NAME}" >> gradle.properties + echo "mavenCentralPassword=${MAVEN_CENTRAL_PASSWORD}" >> gradle.properties + echo "signing.keyId=${SIGNING_KEY_ID}" >> gradle.properties + echo "signing.password=${SIGNING_KEY_PASSWORD}" >> gradle.properties + echo "signing.secretKeyRingFile=${HOME}/secring.gpg" >> gradle.properties + + - name: Setup Xcode + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + + - name: Publish To Maven Central + run: | + ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache diff --git a/README.md b/README.md index c52cd99..b42b56e 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ Jetpack compose [treemap](https://en.wikipedia.org/wiki/Treemapping) chart imple ### Adding to the project Add this to your `dependencies` gradle block: ```gradle -implementation "io.github.overpas:treemap-chart:0.1.2" -implementation "io.github.overpas:treemap-chart-compose:0.1.2" +implementation "io.github.overpas:treemap-chart:0.1.3" +implementation "io.github.overpas:treemap-chart-compose:0.1.3" ``` ### Sample code ```kotlin @@ -48,4 +48,4 @@ fun MyChart() { The code above produces something like this: -For more advanced Kotlin Multiplatform samples check out the /sample directory +For more advanced Kotlin Multiplatform samples check out the [sample](https://github.com/overpas/compose-treemap-chart/tree/master/sample) directory diff --git a/convention-plugins/build.gradle.kts b/convention-plugins/build.gradle.kts index 7aa182e..95a7722 100644 --- a/convention-plugins/build.gradle.kts +++ b/convention-plugins/build.gradle.kts @@ -4,4 +4,5 @@ plugins { dependencies { implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) + implementation(libs.maven.publish.plugin) } diff --git a/convention-plugins/src/main/kotlin/publication.gradle.kts b/convention-plugins/src/main/kotlin/publication.gradle.kts deleted file mode 100644 index 197fd66..0000000 --- a/convention-plugins/src/main/kotlin/publication.gradle.kts +++ /dev/null @@ -1,106 +0,0 @@ -import java.util.Properties - -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.key"] = 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("SIGNING_KEY_ID") - ext["signing.password"] = System.getenv("SIGNING_PASSWORD") - ext["signing.key"] = System.getenv("SIGNING_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("Treemap Chart Compose") - description.set("Jetpack Compose (Multiplatform) treemap chart implementation") - url.set("https://github.com/overpas/compose-treemap-chart") - - licenses { - license { - name.set("MIT") - url.set("https://github.com/overpas/compose-treemap-chart/blob/master/LICENSE.txt") - } - } - developers { - developer { - id.set("overpas") - name.set("Pavel Shurmilov") - email.set("pckeycalculator@gmail.com") - } - } - scm { - connection.set("scm:git:github.com/overpas/compose-treemap-chart.git") - developerConnection.set("scm:git:ssh://github.com/overpas/compose-treemap-chart.git") - url.set("https://github.com/overpas/compose-treemap-chart/tree/master") - } - } - } -} - -// Signing artifacts. Signing.* extra properties values will be used -signing { - useInMemoryPgpKeys( - project.ext["signing.keyId"]?.toString(), - project.ext["signing.key"]?.toString(), - project.ext["signing.password"]?.toString(), - ) - sign(publishing.publications) -} - -tasks.matching { it.name.endsWith("PublicationToSonatypeRepository") } - .configureEach { - dependsOn(tasks.matching { it.name == "signIosArm64Publication" }) - dependsOn(tasks.matching { it.name == "signIosX64Publication" }) - dependsOn(tasks.matching { it.name == "signIosSimulatorArm64Publication" }) - dependsOn(tasks.matching { it.name == "signDesktopPublication" }) - dependsOn(tasks.matching { it.name == "signJsPublication" }) - dependsOn(tasks.matching { it.name == "signKotlinMultiplatformPublication" }) - dependsOn(tasks.matching { it.name == "signAndroidDebugPublication" }) - dependsOn(tasks.matching { it.name == "signAndroidReleasePublication" }) - dependsOn(tasks.matching { it.name == "signWasmJsPublication" }) - } diff --git a/convention-plugins/src/main/kotlin/publish.gradle.kts b/convention-plugins/src/main/kotlin/publish.gradle.kts new file mode 100644 index 0000000..e74432f --- /dev/null +++ b/convention-plugins/src/main/kotlin/publish.gradle.kts @@ -0,0 +1,50 @@ +import com.vanniktech.maven.publish.SonatypeHost + +plugins { + id("com.vanniktech.maven.publish") +} + +mavenPublishing { + // Define coordinates for the published artifact + coordinates( + groupId = properties["lib.group"].toString().also { println(it) }, + artifactId = project.name.also { println(it) }, + version = properties["lib.version"].toString().also { println(it) }, + ) + + // Configure POM metadata for the published artifact + pom { + name.set("Treemap Chart Compose") + description.set("Jetpack Compose (Multiplatform) treemap chart implementation") + url.set("https://github.com/overpas/compose-treemap-chart") + + licenses { + license { + name.set("MIT") + url.set("https://github.com/overpas/compose-treemap-chart/blob/master/LICENSE.txt") + } + } + + // Specify developers information + developers { + developer { + id.set("overpas") + name.set("Pavel Shurmilov") + email.set("pckeycalculator@gmail.com") + } + } + + // Specify SCM information + scm { + connection.set("scm:git:github.com/overpas/compose-treemap-chart.git") + developerConnection.set("scm:git:ssh://github.com/overpas/compose-treemap-chart.git") + url.set("https://github.com/overpas/compose-treemap-chart/tree/master") + } + } + + // Configure publishing to Maven Central + publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) + + // Enable GPG signing for all publications + signAllPublications() +} diff --git a/gradle.properties b/gradle.properties index 487ad55..6c91022 100644 --- a/gradle.properties +++ b/gradle.properties @@ -36,5 +36,7 @@ jvm.version=17 android.minSdk=24 android.compileSdk=34 android.targetSdk=34 -lib.version=0.1.2 -lib.group=io.github.overpas \ No newline at end of file +lib.version=0.1.3 +lib.group=io.github.overpas + +# For manual publication paste the necessary entries from local.properties here in order for maven-publish plugin to work \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2e64395..46cc2ed 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,6 +31,7 @@ androidx-compose-ui-test = "1.7.4" robolectric = "4.13" # Other detekt = '1.23.7' +maven-publish-plugin = "0.30.0" [libraries] # Kotlin @@ -59,6 +60,8 @@ androidx-test-rules = { group = "androidx.test", name = "rules", version.ref = " androidx-compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "androidx-compose-ui-test" } androidx-compose-ui-test-junit4 = { module = "androidx.compose.ui:ui-test-junit4", version.ref = "androidx-compose-ui-test" } robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" } +# Other +maven-publish-plugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "maven-publish-plugin" } [plugins] # Android diff --git a/treemap-chart-compose/build.gradle.kts b/treemap-chart-compose/build.gradle.kts index 3498d1c..0282728 100644 --- a/treemap-chart-compose/build.gradle.kts +++ b/treemap-chart-compose/build.gradle.kts @@ -8,14 +8,12 @@ plugins { alias(libs.plugins.compose) alias(libs.plugins.compose.compiler) alias(libs.plugins.detekt) - id("publication") + id("publish") } group = properties["lib.group"].toString() version = properties["lib.version"].toString() -println("group = $group, version = $version") - android { namespace = "by.overpass.treemapchart.compose" compileSdk = properties["android.compileSdk"].toString().toInt() diff --git a/treemap-chart/build.gradle.kts b/treemap-chart/build.gradle.kts index 8816931..637cc14 100644 --- a/treemap-chart/build.gradle.kts +++ b/treemap-chart/build.gradle.kts @@ -8,7 +8,7 @@ plugins { alias(libs.plugins.compose) alias(libs.plugins.compose.compiler) alias(libs.plugins.detekt) - id("publication") + id("publish") } group = properties["lib.group"].toString()