mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-05 03:41:07 +01:00
Add task to promote artifacts to maven central
This commit is contained in:
parent
33c6ba3602
commit
9a23f0d05f
1 changed files with 50 additions and 0 deletions
50
build.gradle
50
build.gradle
|
|
@ -197,6 +197,56 @@ subprojects {
|
|||
required { signingRequired }
|
||||
sign publishing.publications.mavenJava
|
||||
}
|
||||
|
||||
// see https://github.com/conductor-oss/conductor/blob/main/deploy.gradle#L76-L129
|
||||
task promoteToMavenCentral {
|
||||
group = 'publishing'
|
||||
description = 'Promotes staged artifacts to Maven Central'
|
||||
|
||||
onlyIf {
|
||||
sonatypeCredentialsAvailable && !isSnapshot
|
||||
}
|
||||
|
||||
doLast {
|
||||
// Create base64 encoded token for authentication
|
||||
def token = "${sonatypeUsername}:${sonatypePassword}".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 errorStream = connection.errorStream
|
||||
def errorBody = errorStream ? errorStream.text : "No error body available"
|
||||
def errorMessage = "Failed to promote repository ${repo.key}. Response code: ${responseCode}. Response message: ${connection.responseMessage}. Error body: ${errorBody}"
|
||||
project.logger.error(errorMessage)
|
||||
//throw new GradleException(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tasks.matching { it.name == 'publish' }.configureEach { publishTask ->
|
||||
publishTask.finalizedBy tasks.promoteToMavenCentral
|
||||
}
|
||||
}
|
||||
|
||||
def getGitCommit() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue