|
@@ -13,6 +13,7 @@ import java.io.ByteArrayOutputStream
|
|
|
plugins {
|
|
|
id("io.codearte.nexus-staging") version "0.22.0"
|
|
|
kotlin("jvm")
|
|
|
+ kotlin("plugin.serialization")
|
|
|
}
|
|
|
|
|
|
tasks.register<JavaExec>("runcihelper") {
|
|
@@ -66,28 +67,75 @@ nexusStaging {
|
|
|
}
|
|
|
|
|
|
dependencies {
|
|
|
+ implementation(`ktor-client-okhttp`)
|
|
|
implementation(`kotlinx-serialization-json`)
|
|
|
+ implementation("org.jetbrains.kotlinx", "kotlinx-datetime", "0.4.0")
|
|
|
}
|
|
|
|
|
|
tasks.register("updateSnapshotVersion") {
|
|
|
group = "mirai"
|
|
|
|
|
|
+ dependsOn(tasks.compileKotlin)
|
|
|
+ dependsOn(tasks.compileJava)
|
|
|
+
|
|
|
doLast {
|
|
|
- setProjectVersionForFutureBuilds(snapshotVersion)
|
|
|
+ val out = ByteArrayOutputStream()
|
|
|
+
|
|
|
+ val sha = getSha()
|
|
|
+ val branch = getCurrentGitBranch()
|
|
|
+
|
|
|
+ val result = javaexec {
|
|
|
+ standardOutput = out
|
|
|
+ classpath(sourceSets.main.get().runtimeClasspath)
|
|
|
+ mainClass.set("cihelper.buildIndex.GetNextSnapshotIndex")
|
|
|
+ args(branch, sha)
|
|
|
+ environment(
|
|
|
+ "mirai.build.index.auth.username",
|
|
|
+ System.getenv("MIRAI_BUILD_INDEX_AUTH_USERNAME")
|
|
|
+ ?: project.property("mirai.build.index.auth.username")
|
|
|
+
|
|
|
+ )
|
|
|
+ environment(
|
|
|
+ "mirai.build.index.auth.password",
|
|
|
+ System.getenv("MIRAI_BUILD_INDEX_AUTH_PASSWORD")
|
|
|
+ ?: project.property("mirai.build.index.auth.password")
|
|
|
+ )
|
|
|
+ }
|
|
|
+ result.assertNormalExitValue()
|
|
|
+
|
|
|
+ val resultString = out.toByteArray().decodeToString()
|
|
|
+ val index = resultString
|
|
|
+ .substringAfter("<SNAPSHOT_VERSION_START>", "")
|
|
|
+ .substringBefore("<SNAPSHOT_VERSION_END>", "")
|
|
|
+
|
|
|
+ logger.info("Exec result:")
|
|
|
+ logger.info(resultString)
|
|
|
+
|
|
|
+ if (index.isEmpty()) {
|
|
|
+ throw GradleException("Failed to find version.")
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("Snapshot version index is '$index'")
|
|
|
+ val versionName = "${Versions.project}-$branch-${index}"
|
|
|
+
|
|
|
+ // Add annotation on GitHub Actions build
|
|
|
+ // https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-notice-message
|
|
|
+ println("::notice ::本 commit 的预览版本号: $versionName 在 https://github.com/mamoe/mirai/blob/dev/docs/UsingSnapshots.md 查看如何使用预览版本")
|
|
|
+
|
|
|
+ setProjectVersionForFutureBuilds(versionName)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
tasks.register("publishSnapshotPage") {
|
|
|
doLast {
|
|
|
- UpdateSnapshotPage.run(project, getSha())
|
|
|
+ val sha = getSha()
|
|
|
+ logger.info("CommitRef is $sha")
|
|
|
+ UpdateSnapshotPage.run(project, sha)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-val snapshotVersion by lazy { getSnapshotVersionImpl() }
|
|
|
-
|
|
|
fun getSnapshotVersionImpl(): String {
|
|
|
- val branch = System.getenv("CURRENT_BRANCH_NAME")
|
|
|
+ val branch = getCurrentGitBranch()
|
|
|
logger.info("Current branch name is '$branch'")
|
|
|
val sha = getSha().trim().take(8)
|
|
|
return "${Versions.project}-$branch-${sha}".also {
|
|
@@ -137,7 +185,20 @@ fun getSha(): String {
|
|
|
standardOutput = out
|
|
|
workingDir = rootProject.projectDir
|
|
|
}
|
|
|
- val sha = out.toString()
|
|
|
+ val sha = out.toString().trim()
|
|
|
logger.info("Current commit sha is '$sha'")
|
|
|
return sha
|
|
|
+}
|
|
|
+
|
|
|
+fun getCurrentGitBranch(): String {
|
|
|
+ val out = ByteArrayOutputStream()
|
|
|
+ exec {
|
|
|
+ commandLine("git")
|
|
|
+ args("rev-parse", "--abbrev-ref", "HEAD")
|
|
|
+ standardOutput = out
|
|
|
+ workingDir = rootProject.projectDir
|
|
|
+ }
|
|
|
+ val sha = out.toString().trim()
|
|
|
+ logger.info("Current branch is '$sha'")
|
|
|
+ return sha
|
|
|
}
|