From a379f7990ee759af44ab0c68b841b748219fbbf9 Mon Sep 17 00:00:00 2001 From: MateuszZarembaMongoDB <149502974+MateuszZarembaMongoDB@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:20:52 +0100 Subject: [PATCH 1/4] Add system env variable fetch --- build.gradle | 8 ++++++-- gradle.properties | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 38bff97..9cadb65 100644 --- a/build.gradle +++ b/build.gradle @@ -191,8 +191,8 @@ publishing { url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl credentials { - username = ossrhUsername - password = ossrhPassword + username = System.getenv("OSSRH_USERNAME") + password = System.getenv("OSSRH_PASSWORD") } } } @@ -200,5 +200,9 @@ publishing { signing { required { gradle.taskGraph.hasTask("publish") } + def signingKeyId = System.getenv("SIGNING_KEY_ID") + def signingKey = System.getenv("SIGNING_KEY") + def signingPassword = System.getenv("SIGNING_PASSWORD") + useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) sign publishing.publications.mavenJava } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 7a84135..547d085 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1 @@ version=2.0.2 -signing.keyId=YourKeyId -signing.password=YourPublicKeyPassword -signing.secretKeyRingFile=PathToYourKeyRingFile - -ossrhUsername=your-jira-id -ossrhPassword=your-jira-password From 31a4fb25e79533486a1d1d4d9cb33197d476bfde Mon Sep 17 00:00:00 2001 From: MateuszZarembaMongoDB <149502974+MateuszZarembaMongoDB@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:33:05 +0100 Subject: [PATCH 2/4] Create Publish Workflow --- .github/workflows/publish-workflow.yaml | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/publish-workflow.yaml diff --git a/.github/workflows/publish-workflow.yaml b/.github/workflows/publish-workflow.yaml new file mode 100644 index 0000000..d5b004e --- /dev/null +++ b/.github/workflows/publish-workflow.yaml @@ -0,0 +1,35 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Publish package to the Staging Maven Central Repository +on: + release: + types: [created] +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Java + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + + - name: Publish package + run: ./gradlew publish + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} \ No newline at end of file From 2435bc1678a0589343181304f93811202aef568d Mon Sep 17 00:00:00 2001 From: MateuszZarembaMongoDB <149502974+MateuszZarembaMongoDB@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:06:47 +0100 Subject: [PATCH 3/4] Introduce Automatic Staging publish in Central --- build.gradle | 18 +++++++++--------- gradle.properties | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 9cadb65..a20b324 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ plugins { id("net.ltgt.errorprone") version "3.0.1" apply false id "org.sonarqube" version "4.2.1.3168" id "jacoco" + id "io.github.gradle-nexus.publish-plugin" version "2.0.0-rc-2" } apply(plugin: "java-library"); @@ -184,16 +185,15 @@ publishing { } } } +} + +nexusPublishing { repositories { - maven { - def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" - def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" - url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl - - credentials { - username = System.getenv("OSSRH_USERNAME") - password = System.getenv("OSSRH_PASSWORD") - } + sonatype { //only for users registered in Sonatype after 24 Feb 2021 + nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) + snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) + username = System.getenv("OSSRH_USERNAME") + password = System.getenv("OSSRH_PASSWORD") } } } diff --git a/gradle.properties b/gradle.properties index 547d085..a80dc36 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=2.0.2 +version=2.0.3 From 51d522125edb3c8aa3255c1107e37df623be14f7 Mon Sep 17 00:00:00 2001 From: MateuszZarembaMongoDB <149502974+MateuszZarembaMongoDB@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:09:11 +0100 Subject: [PATCH 4/4] Modify release workflow --- .github/workflows/publish-workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-workflow.yaml b/.github/workflows/publish-workflow.yaml index d5b004e..2375383 100644 --- a/.github/workflows/publish-workflow.yaml +++ b/.github/workflows/publish-workflow.yaml @@ -26,7 +26,7 @@ jobs: uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 - name: Publish package - run: ./gradlew publish + run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository env: OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}