build: use commit time as build time

This commit is contained in:
lisonge 2024-07-16 23:50:55 +08:00
parent 55b1dac875
commit 9b67a5c06d

View File

@ -14,12 +14,14 @@ fun String.runCommand(currentWorkingDir: File = file("./")): String {
data class GitInfo(
val commitId: String,
val commitTime: Long,
val tagName: String?,
)
val gitInfo = try {
GitInfo(
commitId = "git rev-parse HEAD".runCommand(),
commitTime = "git log -1 --format=%ct".runCommand().toLong() * 1000L,
tagName = try {
"git describe --tags --exact-match".runCommand()
} catch (e: Exception) {
@ -64,7 +66,7 @@ android {
useSupportLibrary = true
}
val nowTime = System.currentTimeMillis()
val nowTime = gitInfo?.commitTime ?: 0
buildConfigField("Long", "BUILD_TIME", jsonStringOf(nowTime) + "L")
buildConfigField(
"String",