From f493edfdfbd396c63952d610868c62ccc4490c90 Mon Sep 17 00:00:00 2001 From: Romain Boisselle Date: Thu, 11 Mar 2021 17:53:50 +0100 Subject: [PATCH] New publication configuration (#14) * add Dokka + align POM metadatas with sonatype requirements * update snapshot CI * update JNI publication * update CI scripts * remove maven-metadata-local.xml * add snapshot publication with maven-publish plugin --- .github/workflows/release.yml | 32 +++++++---- .github/workflows/snapshot.yml | 83 +++++++++++++++++------------ .github/workflows/test.yml | 2 +- build.gradle.kts | 94 ++++++++++++++++++++++++++++----- jni/android/build.gradle.kts | 8 +++ jni/build.gradle.kts | 8 +++ jni/jvm/all/build.gradle.kts | 5 ++ jni/jvm/build.gradle.kts | 5 ++ jni/jvm/darwin/build.gradle.kts | 6 +++ jni/jvm/linux/build.gradle.kts | 5 ++ jni/jvm/mingw/build.gradle.kts | 5 ++ 11 files changed, 196 insertions(+), 57 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 48e76c5..1201f43 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,24 +89,38 @@ jobs: BINTRAY_USER: ${{ secrets.bintray_user }} BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} shell: bash - run: ./gradlew publishLinuxPublicationToBintrayRepository :jni:jvm:linux:publishJvmPublicationToBintrayRepository +# ./gradlew publishLinuxPublicationToBintrayRepository :jni:jvm:linux:publishJvmPublicationToBintrayRepository + run: ./gradlew publishLinuxPublicationToMavenLocal :jni:jvm:linux:publishJvmPublicationToMavenLocal - name: Publish Windows if: matrix.os == 'windows-latest' env: BINTRAY_USER: ${{ secrets.bintray_user }} BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} shell: bash - run: ./gradlew :jni:jvm:mingw:publishJvmPublicationToBintrayRepository +# ./gradlew :jni:jvm:mingw:publishJvmPublicationToBintrayRepository + run: ./gradlew :jni:jvm:mingw:publishToMavenLocal - name: Publish MacOS if: matrix.os == 'macOS-latest' env: BINTRAY_USER: ${{ secrets.bintray_user }} BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} shell: bash - run: ./gradlew publish - - name: Discard - if: ${{ failure() || cancelled() }} - env: - BINTRAY_USER: ${{ secrets.bintray_user }} - BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} - run: ./gradlew postBintrayDiscard +# ./gradlew publish + run: ./gradlew publishToMavenLocal + - name: Copy artifact files + run: | + mkdir -p maven-local/release + cp -r ~/.m2/repository/* maven-local/release + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: release + path: | + maven-local + !maven-local/**/maven-metadata-local.xml +# - name: Discard +# if: ${{ failure() || cancelled() }} +# env: +# BINTRAY_USER: ${{ secrets.bintray_user }} +# BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} +# run: ./gradlew postBintrayDiscard diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index 911cde8..f1d6ab0 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -3,7 +3,7 @@ name: Publish snapshot on: push: branches: - - 'snapshot/*' + - 'master' paths-ignore: - '**.md' - '**.adoc' @@ -97,49 +97,64 @@ jobs: BINTRAY_USER: ${{ secrets.bintray_user }} BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} shell: bash - run: ./gradlew publishLinuxPublicationToBintrayRepository :jni:jvm:linux:publishJvmPublicationToBintrayRepository -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} +# ./gradlew publishLinuxPublicationToBintrayRepository :jni:jvm:linux:publishJvmPublicationToBintrayRepository -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} + run: ./gradlew publishLinuxPublicationToMavenLocal :jni:jvm:linux:publishJvmPublicationToMavenLocal -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} - name: Publish Windows if: matrix.os == 'windows-latest' env: BINTRAY_USER: ${{ secrets.bintray_user }} BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} shell: bash - run: ./gradlew :jni:jvm:mingw:publishJvmPublicationToBintrayRepository -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} +# ./gradlew :jni:jvm:mingw:publishJvmPublicationToBintrayRepository -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} + run: ./gradlew :jni:jvm:mingw:publishToMavenLocal -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} - name: Publish MacOS if: matrix.os == 'macOS-latest' env: BINTRAY_USER: ${{ secrets.bintray_user }} BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} shell: bash - run: ./gradlew publish -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} - - name: Discard - if: ${{ failure() || cancelled() }} - env: - BINTRAY_USER: ${{ secrets.bintray_user }} - BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} - run: ./gradlew postBintrayDiscard -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} +# ./gradlew publish -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} + run: ./gradlew publishToMavenLocal -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} + - name: Copy artifact files + shell: bash + run: | + mkdir -p maven-local/snapshot + cp -r ~/.m2/repository/* maven-local/snapshot + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: snapshot + path: | + maven-local + !maven-local/**/maven-metadata-local.xml +# - name: Discard +# if: ${{ failure() || cancelled() }} +# env: +# BINTRAY_USER: ${{ secrets.bintray_user }} +# BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} +# run: ./gradlew postBintrayDiscard -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} - publish: - name: Publish - needs: upload - runs-on: ubuntu-latest - steps: - - name: Check out - uses: actions/checkout@v2 - with: - submodules: 'true' - - name: Cached Gradle - uses: actions/cache@v2 - with: - path: ~/.gradle - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} - restore-keys: ${{ runner.os }}-gradle- - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Publish - env: - BINTRAY_USER: ${{ secrets.bintray_user }} - BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} - run: ./gradlew postBintrayPublish -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} +# publish: +# name: Publish +# needs: upload +# runs-on: ubuntu-latest +# steps: +# - name: Check out +# uses: actions/checkout@v2 +# with: +# submodules: 'true' +# - name: Cached Gradle +# uses: actions/cache@v2 +# with: +# path: ~/.gradle +# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} +# restore-keys: ${{ runner.os }}-gradle- +# - name: Set up JDK 11 +# uses: actions/setup-java@v1 +# with: +# java-version: 11 +# - name: Publish +# env: +# BINTRAY_USER: ${{ secrets.bintray_user }} +# BINTRAY_APIKEY: ${{ secrets.bintray_apikey }} +# run: ./gradlew postBintrayPublish -PsnapshotNumber=${{ github.run_number }} -PgitRef=${{ github.ref }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8c9698..6cdfae2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ on: - '!.github/workflows/test.yml' push: branches: - - 'master' + - '!master' paths-ignore: - '**.md' - '**.adoc' diff --git a/build.gradle.kts b/build.gradle.kts index 07ebb3c..c5c6858 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,9 +6,11 @@ import org.apache.http.impl.auth.BasicScheme import org.apache.http.auth.UsernamePasswordCredentials import org.gradle.internal.os.OperatingSystem import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.dokka.Platform plugins { kotlin("multiplatform") version "1.4.31" + id("org.jetbrains.dokka") version "1.4.20" `maven-publish` } @@ -16,20 +18,23 @@ buildscript { repositories { google() mavenCentral() + jcenter() } dependencies { classpath("com.android.tools.build:gradle:4.0.2") + classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.4.20") } } allprojects { group = "fr.acinq.secp256k1" - version = "0.5.0" + version = "0.5.1-SNAPSHOT" repositories { jcenter() google() + mavenCentral() } } @@ -107,22 +112,30 @@ allprojects { } } -val snapshotNumber: String? by project -val gitRef: String? by project -val eapBranch = gitRef?.split("/")?.last() ?: "dev" -val bintrayVersion = if (snapshotNumber != null) "${project.version}-$eapBranch-$snapshotNumber" else project.version.toString() -val bintrayRepo = if (snapshotNumber != null) "snapshots" else "libs" +// Publication +val bintrayRepo = if (project.version.toString().contains("SNAPSHOT")) "snapshots" else "libs" val bintrayUsername: String? = (properties["bintrayUsername"] as String?) ?: System.getenv("BINTRAY_USER") val bintrayApiKey: String? = (properties["bintrayApiKey"] as String?) ?: System.getenv("BINTRAY_APIKEY") val hasBintray = bintrayUsername != null && bintrayApiKey != null if (!hasBintray) logger.warn("Skipping bintray configuration as bintrayUsername or bintrayApiKey is not defined") +val sonatypeUsername: String? = (properties["sonatypeUsername"] as String?) ?: System.getenv("SONATYPE_USERNAME") +val sonatypePassword: String? = (properties["sonatypePassword"] as String?) ?: System.getenv("SONATYPE_PASSWORD") +val hasSonatype = sonatypeUsername != null && sonatypePassword != null +if (!hasSonatype) logger.warn("Skipping sonatype snapshot configuration as sonatypeUsername or sonatypePassword is not defined") + allprojects { + val javadocJar = tasks.create("javadocJar") { + archiveClassifier.set("javadoc") + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + + // Publication plugins.withId("maven-publish") { publishing { - if (hasBintray) { - repositories { + repositories { + if (hasBintray) { maven { name = "bintray" setUrl("https://api.bintray.com/maven/acinq/$bintrayRepo/${rootProject.name}/;publish=0") @@ -132,16 +145,31 @@ allprojects { } } } + + if (hasSonatype) { + maven { + name = "snapshot" + setUrl("https://oss.sonatype.org/content/repositories/snapshots") + credentials { + username = sonatypeUsername + password = sonatypePassword + } + } + } } publications.withType().configureEach { - version = bintrayVersion + version = project.version.toString() + artifact(javadocJar) pom { + name.set("secp256k1 for Kotlin/Multiplatform") description.set("Bitcoin's secp256k1 library ported to Kotlin/Multiplatform for JVM, Android, iOS & Linux") url.set("https://github.com/ACINQ/secp256k1-kmp") licenses { - name.set("Apache License v2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0") + license { + name.set("Apache License v2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0") + } } issueManagement { system.set("Github") @@ -149,18 +177,58 @@ allprojects { } scm { connection.set("https://github.com/ACINQ/secp256k1-kmp.git") + url.set("https://github.com/ACINQ/secp256k1-kmp") + } + developers { + developer { + name.set("ACINQ") + email.set("hello@acinq.co") + } } } } } } + + if (project.name !in listOf("native", "tests")) { + afterEvaluate { + val dokkaOutputDir = buildDir.resolve("dokka") + + tasks.dokkaHtml { + outputDirectory.set(file(dokkaOutputDir)) + dokkaSourceSets { + configureEach { + val platformName = when (platform.get()) { + Platform.jvm -> "jvm" + Platform.js -> "js" + Platform.native -> "native" + Platform.common -> "common" + } + displayName.set(platformName) + + perPackageOption { + matchingRegex.set(".*\\.internal.*") // will match all .internal packages and sub-packages + suppress.set(true) + } + } + } + } + + val deleteDokkaOutputDir by tasks.register("deleteDokkaOutputDirectory") { + delete(dokkaOutputDir) + } + + javadocJar.dependsOn(deleteDokkaOutputDir, tasks.dokkaHtml) + javadocJar.from(dokkaOutputDir) + } + } } if (hasBintray) { val postBintrayPublish by tasks.creating { doLast { HttpClients.createDefault().use { client -> - val post = HttpPost("https://api.bintray.com/content/acinq/$bintrayRepo/${rootProject.name}/$bintrayVersion/publish").apply { + val post = HttpPost("https://api.bintray.com/content/acinq/$bintrayRepo/${rootProject.name}/${project.version.toString()}/publish").apply { entity = StringEntity("{}", ContentType.APPLICATION_JSON) addHeader(BasicScheme().authenticate(UsernamePasswordCredentials(bintrayUsername, bintrayApiKey), this, null)) } @@ -172,7 +240,7 @@ if (hasBintray) { val postBintrayDiscard by tasks.creating { doLast { HttpClients.createDefault().use { client -> - val post = HttpPost("https://api.bintray.com/content/acinq/$bintrayRepo/${rootProject.name}/$bintrayVersion/publish").apply { + val post = HttpPost("https://api.bintray.com/content/acinq/$bintrayRepo/${rootProject.name}/${project.version.toString()}/publish").apply { entity = StringEntity("{ \"discard\": true }", ContentType.APPLICATION_JSON) addHeader(BasicScheme().authenticate(UsernamePasswordCredentials(bintrayUsername, bintrayApiKey), this, null)) } diff --git a/jni/android/build.gradle.kts b/jni/android/build.gradle.kts index f6de900..a41b830 100644 --- a/jni/android/build.gradle.kts +++ b/jni/android/build.gradle.kts @@ -1,6 +1,9 @@ +import org.jetbrains.dokka.Platform + plugins { id("com.android.library") kotlin("android") + id("org.jetbrains.dokka") `maven-publish` } @@ -53,6 +56,11 @@ afterEvaluate { create("android") { artifactId = "secp256k1-kmp-jni-android" from(components["release"]) + val sourcesJar = task("sourcesJar") { + archiveClassifier.set("sources") + from(android.sourceSets["main"].java.srcDirs) + } + artifact(sourcesJar) } } } diff --git a/jni/build.gradle.kts b/jni/build.gradle.kts index 20d6f5d..613ed86 100644 --- a/jni/build.gradle.kts +++ b/jni/build.gradle.kts @@ -1,5 +1,8 @@ +import org.jetbrains.dokka.Platform + plugins { kotlin("jvm") + id("org.jetbrains.dokka") `maven-publish` } @@ -36,6 +39,11 @@ publishing { create("jvm") { artifactId = "secp256k1-kmp-jni-common" from(components["java"]) + val sourcesJar = task("sourcesJar") { + archiveClassifier.set("sources") + from(sourceSets["main"].allSource) + } + artifact(sourcesJar) } } } diff --git a/jni/jvm/all/build.gradle.kts b/jni/jvm/all/build.gradle.kts index 462ccc7..dd98017 100644 --- a/jni/jvm/all/build.gradle.kts +++ b/jni/jvm/all/build.gradle.kts @@ -1,5 +1,6 @@ plugins { `java-library` + id("org.jetbrains.dokka") `maven-publish` } @@ -14,6 +15,10 @@ publishing { create("jvm") { artifactId = "secp256k1-kmp-jni-jvm" from(components["java"]) + val sourcesJar = task("sourcesJar") { + archiveClassifier.set("sources") + } + artifact(sourcesJar) } } } diff --git a/jni/jvm/build.gradle.kts b/jni/jvm/build.gradle.kts index e1ed8bd..6725781 100644 --- a/jni/jvm/build.gradle.kts +++ b/jni/jvm/build.gradle.kts @@ -1,5 +1,6 @@ plugins { kotlin("jvm") + id("org.jetbrains.dokka") `maven-publish` } @@ -35,6 +36,10 @@ publishing { create("jvm") { artifactId = "secp256k1-kmp-jni-jvm-extract" from(components["java"]) + val sourcesJar = task("sourcesJar") { + archiveClassifier.set("sources") + } + artifact(sourcesJar) } } } diff --git a/jni/jvm/darwin/build.gradle.kts b/jni/jvm/darwin/build.gradle.kts index a3b7156..2b4f90b 100644 --- a/jni/jvm/darwin/build.gradle.kts +++ b/jni/jvm/darwin/build.gradle.kts @@ -1,5 +1,7 @@ plugins { kotlin("jvm") + `java-library` + id("org.jetbrains.dokka") `maven-publish` } @@ -25,6 +27,10 @@ publishing { val pub = create("jvm") { artifactId = "secp256k1-kmp-jni-jvm-darwin" from(components["java"]) + val sourcesJar = task("sourcesJar") { + archiveClassifier.set("sources") + } + artifact(sourcesJar) } if (!org.gradle.internal.os.OperatingSystem.current().isMacOsX) { tasks.withType().all { onlyIf { publication != pub } } diff --git a/jni/jvm/linux/build.gradle.kts b/jni/jvm/linux/build.gradle.kts index 18757e6..aeb14ad 100644 --- a/jni/jvm/linux/build.gradle.kts +++ b/jni/jvm/linux/build.gradle.kts @@ -1,5 +1,6 @@ plugins { kotlin("jvm") + id("org.jetbrains.dokka") `maven-publish` } @@ -25,6 +26,10 @@ publishing { val pub = create("jvm") { artifactId = "secp256k1-kmp-jni-jvm-linux" from(components["java"]) + val sourcesJar = task("sourcesJar") { + archiveClassifier.set("sources") + } + artifact(sourcesJar) } if (!org.gradle.internal.os.OperatingSystem.current().isLinux) { tasks.withType().all { onlyIf { publication != pub } } diff --git a/jni/jvm/mingw/build.gradle.kts b/jni/jvm/mingw/build.gradle.kts index cb7eb2c..6f8eeba 100644 --- a/jni/jvm/mingw/build.gradle.kts +++ b/jni/jvm/mingw/build.gradle.kts @@ -1,5 +1,6 @@ plugins { kotlin("jvm") + id("org.jetbrains.dokka") `maven-publish` } @@ -25,6 +26,10 @@ publishing { val pub = create("jvm") { artifactId = "secp256k1-kmp-jni-jvm-mingw" from(components["java"]) + val sourcesJar = task("sourcesJar") { + archiveClassifier.set("sources") + } + artifact(sourcesJar) } if (!org.gradle.internal.os.OperatingSystem.current().isWindows) { tasks.withType().all { onlyIf { publication != pub } }