Skip to content

Commit

Permalink
refactor(mumu): 优化版本号定义
Browse files Browse the repository at this point in the history
  • Loading branch information
conifercone committed Dec 13, 2024
1 parent 02e0ae9 commit 7d6ac4b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import java.nio.charset.StandardCharsets
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter

plugins {
Expand Down Expand Up @@ -42,13 +43,24 @@ tasks.register<Copy>("installGitHooks") {
val gitHash = providers.exec {
commandLine("git", "rev-parse", "--short", "HEAD")
}.standardOutput.asText.get().trim()
val suffixes = listOf("-alpha", "-beta", "-snapshot", "-dev", "-test", "-pre")
val now: ZonedDateTime = ZonedDateTime.now(ZoneOffset.UTC)
val formatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssXXX")
val formattedTime: String = now.format(formatter)
fun endsWithAny(input: String, suffixes: List<String>): Boolean {
return suffixes.any { input.endsWith(it, ignoreCase = true) }
}

allprojects {

group = findProperty("group")!! as String
val versionString = findProperty("version")!! as String
version =
if (versionString.contains("-")) "$versionString-$gitHash" else versionString
if (endsWithAny(
versionString,
suffixes
)
) "$versionString-$gitHash-$formattedTime" else versionString

repositories {
mavenCentral()
Expand Down

0 comments on commit 7d6ac4b

Please sign in to comment.