Move UpdateSnapshotPage up buildSrc

This commit is contained in:
Karlatemp 2022-05-04 16:55:53 +08:00
parent 8250c3da65
commit 784c78a010
No known key found for this signature in database
GPG Key ID: C6B606FF23D8FED7
2 changed files with 57 additions and 40 deletions

View File

@ -0,0 +1,56 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
import com.google.gson.JsonObject
import org.gradle.api.Project
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
object UpdateSnapshotPage {
fun safeToStr(any: Any?): String = any.toString()
fun run(project: Project, sha: String) {
val token = System.getenv("GH_TOKEN") ?: error("GH_TOKEN not found")
val ver = safeToStr(project.version)
val http = HttpClient.newHttpClient()
val document = project.rootProject.projectDir.resolve("docs/UsingSnapshots.md").let { file ->
kotlin.runCatching { file.readText() }.getOrElse { "" }
}
val content = JsonObject().also { data ->
data.addProperty("name", "Snapshot Build Output")
data.addProperty("head_sha", sha)
data.addProperty("conclusion", "success")
data.add("output", JsonObject().also { output ->
output.addProperty("title", "Snapshot build ($ver)")
output.addProperty("summary", "snapshot version: `$ver`\n\n------\n\n\n$document")
})
}.toString()
http.send(
HttpRequest.newBuilder(URI.create("https://api.github.com/repos/mamoe/mirai/check-runs"))
.POST(HttpRequest.BodyPublishers.ofString(content))
.header("Authorization", "token $token")
.header("Accept", "application/vnd.github.v3+json")
.build(),
HttpResponse.BodyHandlers.ofByteArrayConsumer { rsp ->
if (rsp.isPresent) {
System.out.write(rsp.get())
} else {
println()
println()
}
}
)
(http.executor().orElse(null) as? java.util.concurrent.ExecutorService)?.shutdown()
}
}

View File

@ -6,14 +6,8 @@
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
import com.google.gson.JsonObject
import keys.SecretKeys
import java.io.ByteArrayOutputStream
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpRequest.BodyPublishers
import java.net.http.HttpResponse
plugins {
id("io.codearte.nexus-staging") version "0.22.0"
@ -44,40 +38,7 @@ tasks.register("updateSnapshotVersion") {
tasks.register("publishSnapshotPage") {
doLast {
val token = System.getenv("GH_TOKEN") ?: error("GH_TOKEN not found")
val sha = getSha().trim()
val ver = (project.version as Any?).toString()
val http = HttpClient.newHttpClient()
val document = rootProject.projectDir.resolve("docs/UsingSnapshots.md").let { file ->
kotlin.runCatching { file.readText() }.getOrElse { "" }
}
val content = JsonObject().also { data ->
data.addProperty("name", "Snapshot Build Output")
data.addProperty("head_sha", sha)
data.addProperty("conclusion", "success")
data.add("output", JsonObject().also { output ->
output.addProperty("title", "Snapshot build ($ver)")
output.addProperty("summary", "snapshot version: `$ver`\n\n------\n\n\n$document")
})
}.toString()
http.send(
HttpRequest.newBuilder(URI.create("https://api.github.com/repos/mamoe/mirai/check-runs"))
.POST(BodyPublishers.ofString(content))
.header("Authorization", "token $token")
.header("Accept", "application/vnd.github.v3+json")
.build(),
HttpResponse.BodyHandlers.ofByteArrayConsumer { rsp ->
if (rsp.isPresent) {
System.out.write(rsp.get())
} else {
println()
println()
}
}
)
(http.executor() as? java.util.concurrent.ExecutorService)?.shutdown()
UpdateSnapshotPage.run(project, getSha())
}
}