Skip to content

Commit

Permalink
fix: filter publishing by deactivating tasks
Browse files Browse the repository at this point in the history
...rather than changing task dependencies.

With this change, we can still call ALL tasks of a certain publishing
profile. E.g, we can do 'releaseMavenCentral' or 'releaseDevelopCommit'
(without leading ':'). This is less risky of breaking if Gradle
is called wrongly. And, more importantly, it allows us to again call
all tasks that publish to CGP repositories (not Nexus) and only exist
in the _platform_ projects.

Signed-off-by: Jendrik Johannes <jendrik.johannes@gmail.com>
  • Loading branch information
jjohannes committed Jul 4, 2024
1 parent 230e203 commit 1daadae
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node-zxc-build-release-artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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" })
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.named("publishMavenPublicationToSonatypeRepository") {
enabled = publishingPackageGroup == "com.swirlds"
}

publishing.publications.named<MavenPublication>("maven") {
pom.description =
"Swirlds is a software platform designed to build fully-distributed " +
Expand Down Expand Up @@ -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"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.named("publishMavenPublicationToSonatypeRepository") {
enabled = publishingPackageGroup == "com.hedera"
}

publishing {
publications {
named<MavenPublication>("maven") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ plugins {
group = "com.hedera.hashgraph"

javaPlatform { allowDependencies() }

tasks.register("releaseMavenCentral")

0 comments on commit 1daadae

Please sign in to comment.