Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
71 changes: 71 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,9 +18,8 @@ class PublishConfigPlugin implements Plugin<Project> {
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) {
Expand All @@ -45,62 +43,6 @@ class PublishConfigPlugin implements Plugin<Project> {
}
}

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) {
Expand Down
Loading