From cc76d92f57693c8251dd26ea39296ce9ad65bb90 Mon Sep 17 00:00:00 2001 From: Thomas Vitale Date: Sun, 28 Jan 2024 17:40:53 +0100 Subject: [PATCH] build: Improve publishing workflow Signed-off-by: Thomas Vitale --- .github/workflows/commit-stage.yml | 6 +++++- .github/workflows/release-stage.yml | 7 ++++--- .../src/main/groovy/release-conventions.gradle | 14 +------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/.github/workflows/commit-stage.yml b/.github/workflows/commit-stage.yml index ba9ad81..d15a78e 100644 --- a/.github/workflows/commit-stage.yml +++ b/.github/workflows/commit-stage.yml @@ -32,7 +32,11 @@ jobs: - name: Publish snapshot artifacts if: ${{ github.ref == 'refs/heads/main' }} - run: ./gradlew snapshot + run: | + VERSION=$(./gradlew properties | grep 'version:' | awk '{print $2}') + if [[ $VERSION == *"SNAPSHOT"* ]]; then + ./gradlew publishAllPublicationsToSonatypeSnapshotRepository + fi env: MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }} diff --git a/.github/workflows/release-stage.yml b/.github/workflows/release-stage.yml index acb8745..687f515 100644 --- a/.github/workflows/release-stage.yml +++ b/.github/workflows/release-stage.yml @@ -3,8 +3,9 @@ on: - workflow_dispatch jobs: - build: - name: Build + release: + name: Release + if: ${{ github.ref == 'refs/heads/main' }} runs-on: ubuntu-22.04 permissions: contents: read @@ -26,7 +27,7 @@ jobs: run: ./gradlew build - name: Publish staging artifacts - run: ./gradlew release + run: ./gradlew publishAllPublicationsToSonatypeStagingRepository env: MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }} MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }} diff --git a/buildSrc/src/main/groovy/release-conventions.gradle b/buildSrc/src/main/groovy/release-conventions.gradle index 4a4ab0f..3191679 100644 --- a/buildSrc/src/main/groovy/release-conventions.gradle +++ b/buildSrc/src/main/groovy/release-conventions.gradle @@ -15,8 +15,6 @@ javadoc { options.addStringOption("Xdoclint:none", "-quiet") } -ext.isReleaseVersion = !version.endsWith("SNAPSHOT") - publishing { publications { mavenJava(MavenPublication) { @@ -83,19 +81,9 @@ publishing { } signing { - required { gradle.taskGraph.hasTask("release") } + required { gradle.taskGraph.hasTask("publishAllPublicationsToSonatypeStagingRepository") } def signingSecretKey = findProperty('signingSecretKey') ?: System.getenv("SIGNING_SECRET_KEY") def signingPassphrase = findProperty('signingPassphrase') ?: System.getenv("SIGNING_PASSPHRASE") useInMemoryPgpKeys(signingSecretKey, signingPassphrase) sign publishing.publications.mavenJava } - -tasks.register('snapshot') { - onlyIf { !isReleaseVersion } - finalizedBy 'publishAllPublicationsToSonatypeSnapshotRepository' -} - -tasks.register('release') { - onlyIf { isReleaseVersion } - finalizedBy 'publishAllPublicationsToSonatypeStagingRepository' -}