Publish snapshot pages after built

This commit is contained in:
Karlatemp 2022-04-08 23:58:01 +08:00
parent 2930cba0d6
commit fd2663e60c
No known key found for this signature in database
GPG Key ID: C6B606FF23D8FED7
2 changed files with 50 additions and 4 deletions

View File

@ -22,10 +22,6 @@ jobs:
- run: chmod -R 777 *
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v4.8
- name: Init gradle project
run: ./gradlew clean --scan
@ -56,3 +52,8 @@ jobs:
SNAPSHOTS_PUBLISHING_KEY: ${{ secrets.SNAPSHOTS_PUBLISHING_KEY }}
SNAPSHOTS_PUBLISHING_URL: ${{ secrets.SNAPSHOTS_PUBLISHING_URL }}
CURRENT_BRANCH_NAME: dev
- run: >
./gradlew publishSnapshotPage --info
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -6,8 +6,14 @@
*
* 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"
@ -36,6 +42,45 @@ 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()
}
}
val snapshotVersion by lazy { getSnapshotVersionImpl() }