Skip to content

Commit

Permalink
build: use commit time as build time
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jul 16, 2024
1 parent 55b1dac commit 9b67a5c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 9b67a5c

Please sign in to comment.