Skip to content

Commit 70d9463

Browse files
committed
Also update version code when build.
1 parent 9fe9c22 commit 70d9463

3 files changed

Lines changed: 58 additions & 4 deletions

File tree

app/ios/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ val patchInfoPlist = tasks.register("patchInfoPlist", Task::class) {
383383
group = "run"
384384
description = "Patches Info.plist"
385385

386-
val versionName = project.property("version.name").toString().substringBefore("-")
386+
val versionName = getProperty("version.name").substringBefore("-")
387387
inputs.property("version.name", versionName)
388-
val versionCode = project.property("android.version.code")
388+
val versionCode = getProperty("android.version.code")
389389
inputs.property("version.code", versionCode)
390390

391391
val templateFile = file("Animeko/Info.plist.template.txt")

buildSrc/src/main/kotlin/ciHelperTasks.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,57 @@ object ReleaseArtifactNames {
5151

5252
fun fullVersionFromTag(tag: String): String = tag.removePrefix("v")
5353

54+
// alpha 和 beta 版本不能超过 5 个, 因为只有一位数可以给它用
55+
fun versionCodeFromTag(tag: String): String {
56+
val match = Regex("""^v(\d+)\.(\d+)\.(\d+)(?:-(alpha|beta)(\d+))?$""").matchEntire(tag)
57+
?: throw GradleException("Unsupported tag format: '$tag'")
58+
59+
val major = match.groupValues[1].toIntOrNull()
60+
val minor = match.groupValues[2].toIntOrNull()
61+
val patch = match.groupValues[3].toIntOrNull()
62+
val channel = match.groupValues[4]
63+
val meta = match.groupValues[5].toIntOrNull()
64+
65+
require(major != null && major in 0..9) {
66+
"Major version '$major' in tag '$tag' cannot be encoded into a single digit."
67+
}
68+
require(minor != null && minor in 0..99) {
69+
"Minor version '$minor' in tag '$tag' cannot be encoded into two digits."
70+
}
71+
require(patch != null && patch in 0..9) {
72+
"Patch version '$patch' in tag '$tag' cannot be encoded into a single digit."
73+
}
74+
75+
val metaDigit = when (channel) {
76+
"alpha" -> when (meta) {
77+
1 -> 0
78+
2 -> 1
79+
3 -> 2
80+
4 -> 3
81+
5 -> 4
82+
else -> 0
83+
}
84+
85+
"beta" -> when (meta) {
86+
1 -> 5
87+
2 -> 6
88+
3 -> 7
89+
4 -> 8
90+
5 -> 9
91+
else -> 0
92+
}
93+
94+
else -> 0
95+
}
96+
97+
return buildString(5) {
98+
append(major)
99+
append(minor.toString().padStart(2, '0'))
100+
append(patch)
101+
append(metaDigit)
102+
}
103+
}
104+
54105
fun androidApp(fullVersion: String, arch: String): String = "$appName-$fullVersion-$arch.apk"
55106

56107
fun androidAppQr(fullVersion: String, arch: String, server: String): String =

ci-helper/build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,13 @@ tasks.register("updateDevVersionNameFromGit") {
268268
tasks.register("updateReleaseVersionNameFromGit") {
269269
doLast {
270270
val releaseVersion = ReleaseArtifactNames.fullVersionFromTag(ciTag.get())
271+
val releaseVersionCode = ReleaseArtifactNames.versionCodeFromTag(ciTag.get())
271272
val propertiesText = gradleProperties.readText()
272-
println("New version name: $releaseVersion")
273+
println("New version: $releaseVersion($releaseVersionCode)")
273274
gradleProperties.writeText(
274-
propertiesText.replaceFirst(Regex("version.name=(.+)"), "version.name=$releaseVersion"),
275+
propertiesText
276+
.replaceFirst(Regex("version.name=(.+)"), "version.name=$releaseVersion")
277+
.replaceFirst(Regex("android.version.code=(.+)"), "android.version.code=$releaseVersionCode"),
275278
)
276279
}
277280
}

0 commit comments

Comments
 (0)