From fe69c12245dcf93b782d141aaab4d9212f22b2a9 Mon Sep 17 00:00:00 2001 From: CatCoderr Date: Wed, 9 Oct 2024 01:20:29 +0300 Subject: [PATCH] fix(ci): migrate to new sonatype publisher API --- .github/workflows/build.yaml | 31 ++++++++++--------- build.gradle.kts | 59 +++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6baf753..8ed87c6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -2,13 +2,6 @@ name: Build on: [ push ] -env: - GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }} - GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} - GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} - SONATYPE_USERNAME: ${{ secrets.SONATYPE_OSSRH_DEPLOYER }} - SONATYPE_TOKEN: ${{ secrets.SONATYPE_OSSRH_TOKEN }} - jobs: build: runs-on: ubuntu-latest @@ -23,14 +16,22 @@ jobs: distribution: 'adopt' cache: 'gradle' - - name: Build with Gradle - run: ./gradlew test build --no-daemon + - name: Build and publish with Gradle + if: github.ref == 'refs/heads/master' + env: + JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} + JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} + JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }} + run: ./gradlew -i jreleaserConfig build test publish --no-daemon - - name: Publish to Sonatype + - name: Release if: github.ref == 'refs/heads/master' env: - GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} - GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - run: ./gradlew publish --no-daemon \ No newline at end of file + JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_KEY_PASSPHRASE }} + JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }} + JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + JRELEASER_MAVENCENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + JRELEASER_MAVENCENTRAL_TOKEN: ${{ secrets.SONATYPE_PASSWORD }} + run: ./gradlew -i jreleaserFullRelease --no-daemon \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0c3398c..09304ba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,9 @@ +import org.jreleaser.model.Active + plugins { id("java-library") id("maven-publish") - id("io.github.gradle-nexus.publish-plugin") version "1.3.0" - id("signing") + id("org.jreleaser") version "1.14.0" } group = "me.catcoder" @@ -63,17 +64,49 @@ val javadocJar by tasks.registering(Jar::class) { archiveClassifier.set("javadoc") } -publishing { +jreleaser { + signing { + active = Active.ALWAYS + armored = true + verify = false + } + project { + inceptionYear = "2021" + author("@CatCoderr") + } + deploy { + maven { + mavenCentral.create("sonatype") { + active = Active.ALWAYS + url = "https://central.sonatype.com/api/v1/publisher" + stagingRepository(layout.buildDirectory.dir("staging-deploy").get().toString()) + setAuthorization("Basic") + sign = true + checksums = true + sourceJar = true + javadocJar = true + retryDelay = 60 + } + } + } + + release { + github { + skipRelease = true + skipTag = true + } + } +} + - // Configure all publications +publishing { publications { - create("mavenJava") { + create("release") { from(components["java"]) artifact(javadocJar.get()) - // Provide artifacts information requited by Maven Central pom { name.set("ProtocolSidebar") description.set(project.description) @@ -105,22 +138,14 @@ publishing { } } } -} -nexusPublishing { repositories { - sonatype() + maven { + setUrl(layout.buildDirectory.dir("staging-deploy")) + } } } -signing { - val signingKey = System.getenv("GPG_SECRET_KEY") - val signingPassword = System.getenv("GPG_PASSPHRASE") - - useInMemoryPgpKeys(signingKey, signingPassword) - - sign(publishing.publications["mavenJava"]) -} tasks.withType { options.encoding = "UTF-8"