[repo] Migrate 'preparePublication' task into buildSrc

This commit is contained in:
Yahor Berdnikau
2023-07-02 16:11:31 +02:00
committed by Space Team
parent 7bfe59253f
commit 1fdda8962d
6 changed files with 116 additions and 77 deletions
+1 -10
View File
@@ -540,16 +540,7 @@ allprojects {
}
}
apply {
from("libraries/commonConfiguration.gradle")
}
if (extra.has("isDeployStagingRepoGenerationRequired") &&
project.extra["isDeployStagingRepoGenerationRequired"] as Boolean == true
) {
logger.info("Applying configuration for sonatype release")
project.apply { from("libraries/prepareSonatypeStaging.gradle") }
}
preparePublication()
gradle.taskGraph.whenReady {
fun Boolean.toOnOff(): String = if (this) "on" else "off"
+2
View File
@@ -111,6 +111,8 @@ dependencies {
implementation("net.sf.proguard:proguard-gradle:6.2.2")
implementation("gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.0.1")
implementation("io.ktor:ktor-client-core:${rootProject.extra["versions.ktor-client-core"]}")
implementation("io.ktor:ktor-client-cio:${rootProject.extra["versions.ktor-client-cio"]}")
compileOnly("com.gradle:gradle-enterprise-gradle-plugin:3.12.4")
@@ -0,0 +1,89 @@
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import kotlinx.coroutines.runBlocking
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
fun Project.preparePublication() {
tasks.register("preparePublication") {
assert(project.version != "unspecified")
val repositoryProviders = mapOf<String?, String?>(
"sonatype-nexus-staging" to "sonatype",
"sonatype-nexus-snapshots" to "sonatype"
)
val isRelease: Boolean by extra(!project.version.toString().contains("-SNAPSHOT"))
val repo: String? = properties["deployRepo"]?.toString() ?: properties["deploy-repo"]?.toString()
val repoProvider = repositoryProviders.getOrDefault(repo, repo)
val isSonatypePublish: Boolean by extra(repoProvider == "sonatype")
val isSonatypeRelease: Boolean by extra(isSonatypePublish && isRelease)
val deployRepoUrl = properties["deployRepoUrl"]?.toString() ?: properties["deploy-url"]?.toString()
val deployFolder = properties["deployRepoFolder"]?.toString()
?.let { "file://${rootProject.buildDir}/$it" }
val sonatypeSnapshotsUrl = if (isSonatypePublish && !isRelease) {
"https://oss.sonatype.org/content/repositories/snapshots/"
} else {
null
}
val deployUrlFromParameters = deployRepoUrl ?: deployFolder ?: sonatypeSnapshotsUrl
val isDeployStagingRepoGenerationRequired: Boolean by extra(isSonatypeRelease && deployUrlFromParameters == null)
var repoUrl: String by extra((deployUrlFromParameters ?: "file://${rootProject.buildDir}/repo").toString())
logger.info("Deployment repository preliminary url: $repoUrl ($repoProvider)")
val username: String? by extra(
properties["deployRepoUsername"]?.toString() ?: properties["kotlin.${repoProvider}.user"]?.toString()
)
val password: String? by extra(
properties["deployRepoPassword"]?.toString() ?: properties["kotlin.${repoProvider}.password"]?.toString()
)
if (isDeployStagingRepoGenerationRequired) {
doFirst {
HttpClient().use { client ->
runBlocking {
val sonatypeUsername = requireNotNull(username) {
"Username to authenticate on sonatype staging was not provided!"
}
val sonatypePassword = requireNotNull(password) {
"Password to authenticate on sonatype staging was not provided!"
}
val response = client.post("https://oss.sonatype.org/service/local/staging/profiles/169b36e205a64e/start") {
basicAuth(sonatypeUsername, sonatypePassword)
contentType(ContentType.Application.Xml)
accept(ContentType.Application.Xml)
setBody("<promoteRequest><data><description>Repository for publishing $version</description></data></promoteRequest>")
}
if (response.status.value in 200..299) {
val responseText = response.bodyAsText()
val repoId = responseText
.substringAfter("<stagingRepositoryId>")
.substringBefore("</stagingRepositoryId>")
repoUrl = "https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repoId/"
logger.warn("##teamcity[setParameter name='system.deploy-url' value='$repoUrl']")
} else {
throw GradleException("Failed to connect to sonatype API: ${response.status.description}")
}
}
}
}
}
doLast {
logger.warn("Deployment repository url: $repoUrl")
}
}
}
+24
View File
@@ -7383,12 +7383,24 @@
<sha256 value="fbe8cbfd671a350b03f977794ad3a909662bba118d0d26f15572cd6e80faa167" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.dokka" name="gfm-plugin" version="1.8.10">
<artifact name="gfm-plugin-1.8.10.jar">
<md5 value="82f81e5b40c412abc35ba1a091f0fb54" origin="Generated by Gradle"/>
<sha256 value="69c92f7d1db9cbe19dc300b9a85e7bf77e2fc6d6344f737bcc72cf04189e1a5f" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.dokka" name="javadoc-plugin" version="1.8.10">
<artifact name="javadoc-plugin-1.8.10.jar">
<md5 value="680166100b13f96e8f5883993dc244c1" origin="Generated by Gradle"/>
<sha256 value="0c290796708c02d0fb8497fde558971dc1568309be1a5d0e9594ff9d3927bbda" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.dokka" name="jekyll-plugin" version="1.8.10">
<artifact name="jekyll-plugin-1.8.10.jar">
<md5 value="6d7dacef7a65152a7c559e6e8d3a06fe" origin="Generated by Gradle"/>
<sha256 value="4f3b666dd84b83e6b830a497ec0ceff78c8a2087d306dd75315f79872863b781" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.dokka" name="kotlin-analysis-compiler" version="1.8.10">
<artifact name="kotlin-analysis-compiler-1.8.10.jar">
<md5 value="44a44903e750e59448d75e93b5b76d2f" origin="Generated by Gradle"/>
@@ -8667,12 +8679,24 @@
<sha256 value="634aad3c33567570c9bae7fefdadf3da1be57e050103d77d727f3bdb804c1f26" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlinx" name="kotlinx-coroutines-jdk8" version="1.6.3">
<artifact name="kotlinx-coroutines-jdk8-1.6.3.jar">
<md5 value="856e4df32351082424480f936527ed10" origin="Generated by Gradle"/>
<sha256 value="486c75bd5de94bc9a6b2883a8690c90bf3b702e1d894b40addc069fe0c3e1314" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlinx" name="kotlinx-coroutines-slf4j" version="1.6.1">
<artifact name="kotlinx-coroutines-slf4j-1.6.1.jar">
<md5 value="a6755e8b60d2ac97c71b5870dfd52104" origin="Generated by Gradle"/>
<sha256 value="1ed76fd7117c2e06b5c842343ab70c507fde1de8a328a81891e9a51ebf306652" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlinx" name="kotlinx-coroutines-slf4j" version="1.6.3">
<artifact name="kotlinx-coroutines-slf4j-1.6.3.jar">
<md5 value="3769fab603efbe4a3783619c91a48b3b" origin="Generated by Gradle"/>
<sha256 value="cdd445cceac45203ee24cc7335396f580060e573184b9689573dd101f97f4f6f" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.jetbrains.kotlinx" name="kotlinx-datetime-jvm" version="0.3.1">
<artifact name="kotlinx-datetime-jvm-0.3.1.jar">
<md5 value="7fe856499ef7fcc60f4db75ccc753619" origin="Generated by Gradle"/>
-29
View File
@@ -1,29 +0,0 @@
task preparePublication {
def properties = project.properties
assert project.version != 'unspecified'
Map<String, String> repositoryProviders = ['sonatype-nexus-staging' : 'sonatype', 'sonatype-nexus-snapshots' : 'sonatype']
project.ext.isRelease = !project.version.toString().contains('-SNAPSHOT')
String repo = properties["deployRepo"] ?: properties['deploy-repo']
String repoProvider = repositoryProviders.get(repo, repo)
project.ext.isSonatypePublish = repoProvider == 'sonatype'
project.ext.isSonatypeRelease = isSonatypePublish && isRelease
String deployRepoUrl = properties["deployRepoUrl"] ?: properties["deploy-url"]
String deployFolder = properties["deployRepoFolder"] != null ? "file://${rootProject.buildDir}/${properties["deployRepoFolder"]}" : null
String sonatypeSnapshotsUrl = (isSonatypePublish && !isRelease) ? "https://oss.sonatype.org/content/repositories/snapshots/" : null
String deployUrlFromParameters = deployRepoUrl ?: deployFolder ?: sonatypeSnapshotsUrl
project.ext.isDeployStagingRepoGenerationRequired = project.ext.isSonatypeRelease && deployUrlFromParameters == null
ext.repoUrl = (deployUrlFromParameters ?: "file://${rootProject.buildDir}/repo").toString()
logger.info("Deployment repository preliminary url: ${ext.repoUrl} ($repoProvider)")
ext.username = properties["deployRepoUsername"] ?: properties["kotlin.${repoProvider}.user"]
ext.password = properties["deployRepoPassword"] ?: properties["kotlin.${repoProvider}.password"]
doLast {
println("Deployment repository url: ${ext.repoUrl}")
}
}
-38
View File
@@ -1,38 +0,0 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.2'
}
}
import groovyx.net.http.RESTClient
preparePublication {
doFirst {
def client = new RESTClient()
client.uri = 'https://oss.sonatype.org/service/local/staging/profiles/169b36e205a64e/start'
client.auth.basic(username, password)
def params = [
body: "<promoteRequest><data><description>Repository for publishing $version</description></data></promoteRequest>",
contentType: groovyx.net.http.ContentType.XML,
requestContentType: groovyx.net.http.ContentType.XML
]
def rootNode
try {
def serverResponse = client.post(params)
rootNode = serverResponse.getData()
} catch (groovyx.net.http.HttpResponseException e) {
throw new GradleException(e.getResponse().getData().toString(), e)
}
def repoId = rootNode.data.stagedRepositoryId.text()
ext.repoUrl = "https://oss.sonatype.org/service/local/staging/deployByRepositoryId/$repoId/".toString()
println "##teamcity[setParameter name='system.deploy-url' value='${repoUrl}']"
}
}