改为语义化版本号

This commit is contained in:
HapeLee
2025-09-30 02:02:36 +08:00
parent df23b58d9d
commit c7ecc073ab
2 changed files with 50 additions and 12 deletions
+25 -7
View File
@@ -15,14 +15,31 @@ plugins {
}
apply from: 'download.gradle'
static def releaseTime() {
return new Date().format("yy.MMddHH", TimeZone.getTimeZone("GMT+8"))
ext {
versionMajor = 3
versionMinor = 25
versionPatch = 9
}
def name = "legado"
def version = "3." + releaseTime()
def gitCommits = Integer.parseInt('git rev-list HEAD --count'.execute().text.trim())
ext.versionBuild = gitCommits
ext.versionName = "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}"
def getGitCommitHash() {
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
} catch (Exception ignored) {
return "unknown"
}
}
android {
compileSdk = compile_sdk_version
namespace 'io.legato.kazusa'
@@ -52,9 +69,9 @@ android {
minSdk 26
targetSdk 36
versionCode 10000 + gitCommits
versionName version
versionName project.ext.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
project.ext.set("archivesBaseName", name + "_" + version)
project.ext.set("archivesBaseName", name + "_" + versionName)
buildConfigField "String", "Cronet_Version", "\"$CronetVersion\""
buildConfigField "String", "Cronet_Main_Version", "\"$CronetMainVersion\""
@@ -98,7 +115,7 @@ android {
manifestPlaceholders.put("app_name", "@string/app_name")
//applicationIdSuffix '.debug'
versionNameSuffix 'debug'
versionNameSuffix "_debug-${getGitCommitHash()}"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro', 'cronet-proguard-rules.pro'
}
@@ -127,7 +144,8 @@ android {
variant.outputs.configureEach { output ->
def abi = output.getFilter(com.android.build.OutputFile.ABI)
def flavor = variant.productFlavors[0].name
def apkName = "${name}_${flavor}_${defaultConfig.versionName}"
def baseVersionName = variant.versionName
def apkName = "${name}_${flavor}_${baseVersionName}"
if (abi != null) {
apkName += "_${abi}"
}
@@ -80,14 +80,34 @@ object AppUpdateGitHub : AppUpdate.AppUpdateInterface {
}
fun String.versionCompare(other: String): Int {
val thisParts = this.split(".")
val otherParts = other.split(".")
val regex = Regex("""(\d+)|(\D+)""")
val thisParts = regex.findAll(this).map { it.value }.toList()
val otherParts = regex.findAll(other).map { it.value }.toList()
val maxLength = maxOf(thisParts.size, otherParts.size)
for (i in 0 until maxLength) {
val thisPart = thisParts.getOrNull(i)?.toIntOrNull() ?: 0
val otherPart = otherParts.getOrNull(i)?.toIntOrNull() ?: 0
if (thisPart != otherPart) return thisPart - otherPart
val a = thisParts.getOrNull(i)
val b = otherParts.getOrNull(i)
if (a == null) return -1
if (b == null) return 1
val isANum = a.all { it.isDigit() }
val isBNum = b.all { it.isDigit() }
if (isANum && a.length > 1 && a.startsWith("0")) return -1
if (isBNum && b.length > 1 && b.startsWith("0")) return 1
val cmp = if (isANum && isBNum) {
a.toInt() - b.toInt()
} else {
a.compareTo(b)
}
if (cmp != 0) return cmp
}
return 0
}
}