From 1d87c5ba0e3036387305bc1b30d05ca20123b7fd Mon Sep 17 00:00:00 2001 From: Chris Hagglund Date: Tue, 24 Nov 2026 10:04:43 -0600 Subject: [PATCH] fix(publish): promote to Maven Central once per release, not once per module PublishConfigPlugin created promoteToMavenCentral in every module that applies it and made it finalize that module's publish. All six modules upload into the one shared org.conductoross--default-repository, so each release promoted it six times: six Central deployments against the org's monthly release quota, with the first five running before the remaining modules had uploaded. The v6.0.3.rc1 publish log shows six "Promoting repository" lines for the same key. Move the task to one root-level task that mustRunAfter every module's publish, and run "publish promoteToMavenCentral" in one invocation in publish-release.yml. This mirrors conductor-oss/conductor#1826. The promote still fails the build on a non-200 response. Also pass -PmavenCentral without a value. The old value came from a workflow_dispatch input that a release event never sets. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish-release.yml | 7 +- build.gradle | 71 +++++++++++++++++++ .../gradle/PublishConfigPlugin.groovy | 62 +--------------- 3 files changed, 78 insertions(+), 62 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 3ce3d050d..0ec719455 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -24,11 +24,14 @@ jobs: distribution: 'zulu' java-version: '21' - name: Publish + # `publish` uploads every module into the single shared staging repository; + # `promoteToMavenCentral` then promotes it ONCE. Running both in one invocation + # lets `mustRunAfter` order promote last: one Central deployment per release. run: | - export VERSION="${{github.ref_name}}" + export VERSION="${{github.ref_name}}" export CONDUCTOR_CLIENT_VERSION=`echo ${VERSION:1}` echo Publishing version $CONDUCTOR_CLIENT_VERSION - ./gradlew publish -Pversion=$CONDUCTOR_CLIENT_VERSION -PmavenCentral=${{ github.event.inputs.maven_central }} -Pusername=${{ secrets.SONATYPE_USERNAME }} -Ppassword=${{ secrets.SONATYPE_PASSWORD }} + ./gradlew publish promoteToMavenCentral -Pversion=$CONDUCTOR_CLIENT_VERSION -PmavenCentral -Pusername=${{ secrets.SONATYPE_USERNAME }} -Ppassword=${{ secrets.SONATYPE_PASSWORD }} env: ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNING_KEY_ID }} diff --git a/build.gradle b/build.gradle index 58dbe98a7..7d8d6ac5e 100644 --- a/build.gradle +++ b/build.gradle @@ -100,3 +100,74 @@ configure(subprojects.findAll { it.name in publishedProjects }) { resolutionStrategy.activateDependencyLocking() } } + +// Promote staged artifacts to Maven Central -- ONCE for the whole build. +// +// Every published module uploads into the single shared staging repository +// (`org.conductoross--default-repository`), so promotion has to happen exactly +// once, after all of them have uploaded. This task used to be created by +// PublishConfigPlugin in each module and `finalizedBy` that module's `publish`, +// which promoted the shared repository once per module: 6 Central deployments +// per release, each counting against the org's monthly release quota, and all +// but the last running before the remaining modules had uploaded. Conductor had +// the same bug (conductor-oss/conductor#1826). +// +// Run it after `publish` in the same invocation: +// ./gradlew publish promoteToMavenCentral -PmavenCentral ... +// `mustRunAfter` makes it execute last, once every upload is staged. +tasks.register('promoteToMavenCentral') { + group = 'publishing' + description = 'Promotes staged artifacts to Maven Central (once for the whole build)' + + mustRunAfter(subprojects.collect { sp -> sp.tasks.matching { it.name == 'publish' } }) + + onlyIf { + project.hasProperty('mavenCentral') && + project.hasProperty('username') && + project.hasProperty('password') && + !project.version.toString().endsWith('-SNAPSHOT') + } + + doLast { + def username = project.properties['username'] + def password = project.properties['password'] + + // Create base64 encoded token for authentication + def token = "${username}:${password}".bytes.encodeBase64().toString() + + // Get open staging repositories + def response = new URL("https://ossrh-staging-api.central.sonatype.com/manual/search/repositories") + .openConnection() + response.setRequestProperty("Authorization", "Basic ${token}") + response.setRequestProperty("Content-Type", "application/json") + + def repositories = new groovy.json.JsonSlurper().parse(response.inputStream) + + def openRepositories = repositories.repositories.findAll { it.state == "open" } + if (openRepositories.isEmpty()) { + project.logger.lifecycle("No open staging repositories to promote.") + return + } + + // A normal release has exactly one (the shared default repository); iterating + // also promotes any left open by an earlier failed run. + openRepositories.each { repo -> + project.logger.lifecycle("Promoting repository ${repo.key}") + + def promoteUrl = new URL("https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/${repo.key}?publishing_type=automatic") + def connection = promoteUrl.openConnection() + connection.setRequestMethod("POST") + connection.setRequestProperty("Authorization", "Basic ${token}") + connection.setRequestProperty("Content-Type", "application/json") + + def responseCode = connection.responseCode + if (responseCode == 200) { + project.logger.lifecycle("Successfully promoted repository ${repo.key}") + } else { + def errorMessage = "Failed to promote repository ${repo.key}. Response code: ${responseCode}. Response: ${connection.responseMessage}" + project.logger.error(errorMessage) + throw new GradleException(errorMessage) + } + } + } +} diff --git a/buildSrc/src/main/groovy/io/orkes/conductor/gradle/PublishConfigPlugin.groovy b/buildSrc/src/main/groovy/io/orkes/conductor/gradle/PublishConfigPlugin.groovy index f544c608e..97e17396f 100644 --- a/buildSrc/src/main/groovy/io/orkes/conductor/gradle/PublishConfigPlugin.groovy +++ b/buildSrc/src/main/groovy/io/orkes/conductor/gradle/PublishConfigPlugin.groovy @@ -2,7 +2,6 @@ package io.orkes.conductor.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.GradleException import org.gradle.api.publish.maven.plugins.MavenPublishPlugin import org.gradle.plugins.signing.SigningPlugin import org.gradle.api.publish.maven.MavenPublication @@ -19,9 +18,8 @@ class PublishConfigPlugin implements Plugin { project.plugins.withType(SigningPlugin) { signingConfig(project) } - - // Add Maven Central promotion task - addMavenCentralPromotionTask(project) + // Promotion to Maven Central is the root project's promoteToMavenCentral task, + // run once per build rather than once per module. } def publishingConfig(Project project) { @@ -45,62 +43,6 @@ class PublishConfigPlugin implements Plugin { } } - def addMavenCentralPromotionTask(Project project) { - project.task('promoteToMavenCentral') { - group = 'publishing' - description = 'Promotes staged artifacts to Maven Central' - - onlyIf { - project.hasProperty('mavenCentral') && - project.hasProperty('username') && - project.hasProperty('password') && - !project.version.endsWith('-SNAPSHOT') - } - - doLast { - def username = project.properties['username'] - def password = project.properties['password'] - - // Create base64 encoded token for authentication - def token = "${username}:${password}".bytes.encodeBase64().toString() - - // Get open staging repositories - def response = new URL("https://ossrh-staging-api.central.sonatype.com/manual/search/repositories") - .openConnection() - response.setRequestProperty("Authorization", "Basic ${token}") - response.setRequestProperty("Content-Type", "application/json") - - def repositories = new groovy.json.JsonSlurper().parse(response.inputStream) - - // Promote each open repository - repositories.repositories.each { repo -> - if (repo.state == "open") { - project.logger.lifecycle("Promoting repository ${repo.key}") - - def promoteUrl = new URL("https://ossrh-staging-api.central.sonatype.com/manual/upload/repository/${repo.key}?publishing_type=automatic") - def connection = promoteUrl.openConnection() - connection.setRequestMethod("POST") - connection.setRequestProperty("Authorization", "Basic ${token}") - connection.setRequestProperty("Content-Type", "application/json") - - def responseCode = connection.responseCode - if (responseCode == 200) { - project.logger.lifecycle("Successfully promoted repository ${repo.key}") - } else { - def errorMessage = "Failed to promote repository ${repo.key}. Response code: ${responseCode}. Response: ${connection.responseMessage}" - project.logger.error(errorMessage) - throw new GradleException(errorMessage) - } - } - } - } - } - - project.tasks.matching { it.name == 'publish' }.configureEach { publishTask -> - publishTask.finalizedBy project.tasks.promoteToMavenCentral - } - } - def publicationConfig(Project project) { return { mavenJava(MavenPublication) {