Skip to content

Commit 6b58370

Browse files
authored
fix(release): add task to check Maven Central Portal plugin classpath (#5416)
1 parent 0fb1e0e commit 6b58370

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

build.gradle.kts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
import Libs.alchemist
1111
import Libs.incarnation
1212
import com.github.spotbugs.snom.SpotBugsTask
13+
import com.sun.net.httpserver.HttpExchange
14+
import com.sun.net.httpserver.HttpServer
1315
import dev.detekt.gradle.Detekt
1416
import it.unibo.alchemist.build.id
1517
import it.unibo.alchemist.build.isInCI
1618
import it.unibo.alchemist.build.isMac
1719
import it.unibo.alchemist.build.isWindows
20+
import java.net.InetSocketAddress
21+
import kotlinx.coroutines.runBlocking
22+
import org.danilopianini.gradle.mavencentral.portal.PublishPortalDeployment
23+
import org.gradle.api.internal.ConventionTask
1824
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
1925
import org.jetbrains.dokka.gradle.AbstractDokkaTask
2026
import org.jetbrains.dokka.gradle.tasks.DokkaBaseTask
@@ -161,6 +167,57 @@ dependencies {
161167
dokkaGlobalClasspath(alchemist("full"))
162168
}
163169

170+
val checkMavenCentralPortalPluginClasspath by tasks.registering {
171+
group = LifecycleBasePlugin.VERIFICATION_GROUP
172+
description = "Checks that the Maven Central Portal publishing plugin can upload to a local fake endpoint."
173+
val outputFile = layout.buildDirectory.file("reports/checkMavenCentralPortalPluginClasspath/result.txt")
174+
inputs.property("publishOnCentralPluginVersion", libs.plugins.publishOnCentral.get().version.requiredVersion)
175+
outputs.file(outputFile)
176+
doLast {
177+
val server = HttpServer.create(InetSocketAddress("127.0.0.1", 0), 0)
178+
server.createContext("/api/v1/publisher/upload") { exchange ->
179+
exchange.use {
180+
check(exchange.requestMethod == "POST") {
181+
"Expected POST to ${exchange.requestURI}, received ${exchange.requestMethod}"
182+
}
183+
exchange.requestBody.use { it.readBytes() }
184+
exchange.respond(201, "local-deployment-id")
185+
}
186+
}
187+
server.start()
188+
try {
189+
val localPortal = "http://127.0.0.1:${server.address.port}/"
190+
val bundle = temporaryDir.resolve("maven-central-portal-bundle.zip").apply {
191+
parentFile.mkdirs()
192+
writeBytes(byteArrayOf(0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0))
193+
}
194+
val deployment = PublishPortalDeployment(
195+
project = project,
196+
baseUrl = localPortal,
197+
user = providers.provider { "local-user" },
198+
password = providers.provider { "local-password" },
199+
zipTask = tasks.named<ConventionTask>("zipMavenCentralPortalPublication"),
200+
)
201+
val deploymentId = runBlocking {
202+
deployment.upload(bundle, releaseAfterUpload = false)
203+
}
204+
check(deploymentId == "local-deployment-id") {
205+
"Unexpected local Maven Central Portal deployment id: $deploymentId"
206+
}
207+
outputFile.get().asFile.apply {
208+
parentFile.mkdirs()
209+
writeText(deploymentId)
210+
}
211+
} finally {
212+
server.stop(0)
213+
}
214+
}
215+
}
216+
217+
tasks.check {
218+
dependsOn(checkMavenCentralPortalPluginClasspath)
219+
}
220+
164221
tasks.matching { it.name == "kotlinStoreYarnLock" }.configureEach {
165222
dependsOn(rootProject.tasks.named("kotlinUpgradeYarnLock"))
166223
}
@@ -239,3 +296,10 @@ val performWebsiteStringReplacements by tasks.registering {
239296
tasks.hugoBuild.configure {
240297
finalizedBy(performWebsiteStringReplacements)
241298
}
299+
300+
private fun HttpExchange.respond(statusCode: Int, body: String) {
301+
val response = body.toByteArray()
302+
responseHeaders.add("Content-Type", "text/plain; charset=utf-8")
303+
sendResponseHeaders(statusCode, response.size.toLong())
304+
responseBody.use { it.write(response) }
305+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", versi
193193
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
194194
ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
195195
multiJvmTesting = "org.danilopianini.multi-jvm-test-plugin:4.5.1"
196-
publishOnCentral = "org.danilopianini.publish-on-central:9.2.5"
196+
publishOnCentral = "org.danilopianini.publish-on-central:9.2.4"
197197
scalafmt = "cz.augi.gradle.scalafmt:1.21.5"
198198
shadowJar = "com.gradleup.shadow:9.4.2"
199199
taskTree = "com.dorongold.task-tree:4.0.1"

0 commit comments

Comments
 (0)