From 795618948d40663b468fa5b1fefe62d10b339a18 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Mon, 8 Jul 2024 18:36:02 +0200 Subject: [PATCH] build: filter publishing by deactivating tasks (#14160) Signed-off-by: Jendrik Johannes --- .../node-zxc-build-release-artifact.yaml | 4 +-- .../com.hedera.gradle.lifecycle.gradle.kts | 12 --------- ...com.hedera.gradle.nexus-publish.gradle.kts | 22 +++------------- ....hedera.gradle.platform-publish.gradle.kts | 25 ++++++++----------- ....hedera.gradle.services-publish.gradle.kts | 8 ++++++ .../com.hedera.gradle.versions.gradle.kts | 2 ++ 6 files changed, 27 insertions(+), 46 deletions(-) diff --git a/.github/workflows/node-zxc-build-release-artifact.yaml b/.github/workflows/node-zxc-build-release-artifact.yaml index 5c792654445e..14e3a37d8247 100644 --- a/.github/workflows/node-zxc-build-release-artifact.yaml +++ b/.github/workflows/node-zxc-build-release-artifact.yaml @@ -841,7 +841,7 @@ jobs: NEXUS_PASSWORD: ${{ secrets.sdk-ossrh-password }} with: gradle-version: ${{ inputs.gradle-version }} - arguments: ":release${{ inputs.release-profile }} -PpublishingPackageGroup=com.swirlds --scan -PpublishSigningEnabled=true --no-configuration-cache" + arguments: "release${{ inputs.release-profile }} -PpublishingPackageGroup=com.swirlds --scan -PpublishSigningEnabled=true --no-configuration-cache" - name: Gradle Publish Services to ${{ inputs.version-policy == 'specified' && 'Maven Central' || 'Google Artifact Registry' }} (${{ inputs.release-profile }}) uses: gradle/gradle-build-action@29c0906b64b8fc82467890bfb7a0a7ef34bda89e # v3.1.0 @@ -851,7 +851,7 @@ jobs: NEXUS_PASSWORD: ${{ secrets.svcs-ossrh-password }} with: gradle-version: ${{ inputs.gradle-version }} - arguments: ":release${{ inputs.release-profile }} -PpublishingPackageGroup=com.hedera --scan -PpublishSigningEnabled=true --no-configuration-cache" + arguments: "release${{ inputs.release-profile }} -PpublishingPackageGroup=com.hedera --scan -PpublishSigningEnabled=true --no-configuration-cache" - name: Upload SDK Release Archives if: ${{ inputs.dry-run-enabled != true && inputs.version-policy == 'specified' && !cancelled() && !failure() }} diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.lifecycle.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.lifecycle.gradle.kts index 01ea9c9dace9..c0e1aa4fd83c 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.lifecycle.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.lifecycle.gradle.kts @@ -37,15 +37,3 @@ tasks.register("qualityGate") { } tasks.register("releaseMavenCentral") - -// Register these empty tasks: -// https://github.com/hashgraph/hedera-services/blob/63641ffdab4ec13759b901a58682f95b64bd4651/gradle/plugins/src/main/kotlin/com.hedera.gradle.platform-publish.gradle.kts#L70-L86 -tasks.register("releaseAdhocCommit") - -tasks.register("releaseDevelopCommit") - -tasks.register("releaseDevelopDailySnapshot") - -tasks.register("releaseDevelopSnapshot") - -tasks.register("releasePrereleaseChannel") diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.nexus-publish.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.nexus-publish.gradle.kts index 22b33a1c0f3e..182be0a43f10 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.nexus-publish.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.nexus-publish.gradle.kts @@ -37,20 +37,10 @@ nexusPublishing { } } -// 'platform' and 'services' need to be published separately as they use different credentials -val platformPublishTasks = - subprojects.filter { it.name.startsWith("swirlds") }.map { ":${it.name}:releaseMavenCentral" } -val servicesPublishTasks = - subprojects.filter { !it.name.startsWith("swirlds") }.map { ":${it.name}:releaseMavenCentral" } - tasks.named("closeSonatypeStagingRepository") { - // The publishing of all components to Maven Central is automatically done before close - // (which is done before release). - if (isPlatformPublish) { - dependsOn(platformPublishTasks) - } else { - dependsOn(servicesPublishTasks) - } + // The publishing of all components to Maven Central is automatically done before close (which + // is done before release). + dependsOn(subprojects.map { ":${it.name}:releaseMavenCentral" }) } tasks.named("releaseMavenCentral") { @@ -60,9 +50,5 @@ tasks.named("releaseMavenCentral") { tasks.register("releaseMavenCentralSnapshot") { group = "release" - if (isPlatformPublish) { - dependsOn(platformPublishTasks) - } else { - dependsOn(servicesPublishTasks) - } + dependsOn(subprojects.map { ":${it.name}:releaseMavenCentral" }) } diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.platform-publish.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.platform-publish.gradle.kts index b16e3ae609f2..79fd23a0ad23 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.platform-publish.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.platform-publish.gradle.kts @@ -31,6 +31,14 @@ if ( apply(plugin = "com.google.cloud.artifactregistry.gradle-plugin") } +// Publishing tasks are only enabled if we publish to the matching group. +// Otherwise, Nexus configuration and credentials do not fit. +val publishingPackageGroup = providers.gradleProperty("publishingPackageGroup").getOrElse("") + +tasks.withType().configureEach { + enabled = publishingPackageGroup == "com.swirlds" +} + publishing.publications.named("maven") { pom.description = "Swirlds is a software platform designed to build fully-distributed " + @@ -88,19 +96,8 @@ publishing.repositories { // Register one 'release*' task for each publishing repository publishing.repositories.all { val ucName = name.replaceFirstChar { it.titlecase() } - val taskName = "release$ucName" - - // Register the task if it is not already registered - if (!tasks.names.contains(taskName)) { - tasks.register(taskName) { - group = "release" - dependsOn(tasks.named("publishMavenPublicationTo${ucName}Repository")) - } - } else { - // If the task is already registered, we just add the group & dependency - tasks.named(taskName) { - group = "release" - dependsOn(tasks.named("publishMavenPublicationTo${ucName}Repository")) - } + tasks.register("release$ucName") { + group = "release" + dependsOn(tasks.named("publishMavenPublicationTo${ucName}Repository")) } } diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.services-publish.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.services-publish.gradle.kts index c5ea8dd91531..4bae581a0fd3 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.services-publish.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.services-publish.gradle.kts @@ -19,6 +19,14 @@ plugins { id("com.hedera.gradle.maven-publish") } +// Publishing tasks are only enabled if we publish to the matching group. +// Otherwise, Nexus configuration and credentials do not fit. +val publishingPackageGroup = providers.gradleProperty("publishingPackageGroup").getOrElse("") + +tasks.withType().configureEach { + enabled = publishingPackageGroup == "com.hedera" +} + publishing { publications { named("maven") { diff --git a/gradle/plugins/src/main/kotlin/com.hedera.gradle.versions.gradle.kts b/gradle/plugins/src/main/kotlin/com.hedera.gradle.versions.gradle.kts index bda11bfbe12b..02fffa7ac885 100644 --- a/gradle/plugins/src/main/kotlin/com.hedera.gradle.versions.gradle.kts +++ b/gradle/plugins/src/main/kotlin/com.hedera.gradle.versions.gradle.kts @@ -24,3 +24,5 @@ plugins { group = "com.hedera.hashgraph" javaPlatform { allowDependencies() } + +tasks.register("releaseMavenCentral")