From 05c2f7ea29a40127ba082df6241db8d8bd0194e9 Mon Sep 17 00:00:00 2001 From: Alex Arvanitidis Date: Wed, 13 Nov 2024 14:07:52 +0200 Subject: [PATCH] feat: release on maven-central (#4) * make openapi generate depend on sourcesJar * feat: add proper signing for jreleaser * feat: add proper signing for jreleaser * fix: use only env vars * fix: add description * fix: set correct distributions * fix: attempt to release * fix: split build into steps * fix: build and release in one go * fix: pass secrets to signing module * fix: base64 decode secrets * fix: base64 decode secrets * fix: check if newlines is the problem * fix: credentials * fix: signing keys * fix: remove oss repository * fix: publish to local repository staged * fix: path of staging repository * fix: add scm section * fix: rename artifact and try to reupload * fix: name distribution properly * fix: apply maven central rules * fix: rename app to sonatype * fix: latest working build.gradle.kts * fix: remove build from PR, run only on tags --- .github/workflows/publish.yml | 38 ++++++++--------- build.gradle.kts | 79 ++++++++++++++++++++--------------- 2 files changed, 64 insertions(+), 53 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a326a91..2c5c055 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,7 +3,7 @@ name: Publish to Maven Central on: push: tags: - - 'v*' + - '*' workflow_dispatch: jobs: @@ -27,25 +27,23 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2 - - name: Build with Gradle - run: ./gradlew build - - - name: Setup GPG - env: - GPG_PRIVATE_KEY: ${{ secrets.GPG_SIGNING_KEY }} - GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSWORD }} - run: | - echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import - echo "allow-preset-passphrase" > ~/.gnupg/gpg-agent.conf - echo "default-cache-ttl 34560000" >> ~/.gnupg/gpg-agent.conf - gpg-connect-agent reloadagent /bye - - - name: Release to Maven Central + - name: Check release configuration env: - JRELEASER_NEXUS2_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - JRELEASER_NEXUS2_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSWORD }} - JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }} - JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SIGNING_KEY }} + JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }} + JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }} + JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }} + JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }} JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: ./gradlew jreleaserPublish + + - name: Build and Publish + env: + JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }} + JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.JRELEASER_GPG_PUBLIC_KEY }} + JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }} + JRELEASER_GPG_PASSPHRASE: ${{ secrets.JRELEASER_GPG_PASSPHRASE }} + JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./gradlew publish jreleaserFullRelease + diff --git a/build.gradle.kts b/build.gradle.kts index b3356db..fce55b8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -75,84 +75,97 @@ openApiGenerate { ) } -// Publishing + +tasks.getByName("openApiGenerate").dependsOn(tasks.named("sourcesJar")) + + jreleaser { signing { setActive("ALWAYS") armored = true } - project { - authors.set(listOf("UPCI NTUA")) - license.set("MIT") - links { - homepage = "https://api.jaqpot.org" - } - inceptionYear = "2024" + + checksum { + // The name of the grouping checksums file. + // Defaults to `checksums.txt`. + // + name.set("{{projectName}}-{{projectVersion}}_checksums.txt") + + // Uploads individual checksum files. + // Defaults to `false`. + // + individual = true + + // Whether to checksum artifacts in the `distributions` section or not. + // Defaults to `true`. + // + artifacts = true + + // Whether to checksum files in the `files` section or not. + // Defaults to `true`. + // + files = true } deploy { maven { mavenCentral { - register("app") { + register("sonatype") { setActive("ALWAYS") url.set("https://central.sonatype.com/api/v1/publisher") - stagingRepository("target/staging-deploy") + stagingRepository("${layout.buildDirectory.get()}/staging-deploy") username = System.getenv("SONATYPE_USERNAME") password = System.getenv("SONATYPE_PASSWORD") + applyMavenCentralRules = true + verifyPom = true } } } } - - - distributions { - register("app") { - artifact { - path.set(file("build/distributions/{{distributionName}}-{{projectVersion}}.zip")) - } - } - } } - publishing { publications { create("mavenJava") { - artifactId = "jaqpot-kotlin-sdk" + artifactId = "kotlin-sdk" from(components["java"]) pom { name.set("Jaqpot Kotlin SDK") description.set("Java/Kotlin SDK for the Jaqpot API") - url.set("https://github.com/ntua-unit-of-control-and-informatics/jaqpot-kotlin-sdk") + url.set("https://github.com/ntua-unit-of-control-and-informatics/kotlin-sdk") licenses { license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + name.set("MIT License") + url.set("https://opensource.org/licenses/MIT") + distribution.set("repo") } } developers { developer { - id.set("your-username") - name.set("Your Name") - email.set("your.email@example.com") + id.set("upci") + name.set("Alex Arvanitidis") + email.set("upci.ntua@gmail.com") } } + scm { + connection.set("scm:git:git://github.com/ntua-unit-of-control-and-informatics/jaqpot-kotlin-sdk.git") + developerConnection.set("scm:git:ssh://github.com:ntua-unit-of-control-and-informatics/jaqpot-kotlin-sdk.git") + url.set("https://github.com/ntua-unit-of-control-and-informatics/jaqpot-kotlin-sdk") + } } } } repositories { maven { - name = "OSSRH" - url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") - credentials { - username = System.getenv("OSSRH_USERNAME") - password = System.getenv("OSSRH_PASSWORD") - } + url = layout.buildDirectory.dir("staging-deploy").get().asFile.toURI() } } } signing { + val signingKey = System.getenv("JRELEASER_GPG_SECRET_KEY") + val signingPassword = System.getenv("JRELEASER_GPG_PASSPHRASE") + useInMemoryPgpKeys(signingKey, signingPassword) sign(publishing.publications["mavenJava"]) }