From 0721d56d2a55c042f52b3faba03e89d9e143edee Mon Sep 17 00:00:00 2001 From: 5ec1cff Date: Fri, 4 Oct 2024 11:35:00 +0800 Subject: [PATCH] use git commit count as versionCode --- app/build.gradle.kts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1ccf7a5..5355efc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,3 +1,4 @@ +import java.io.ByteArrayOutputStream import java.io.FileInputStream import java.util.Properties @@ -13,6 +14,18 @@ val keystoreProperties = if (keystorePropertiesFile.exists() && keystoreProperti } } else null +fun String.execute(currentWorkingDir: File = file("./")): String { + val byteOut = ByteArrayOutputStream() + project.exec { + workingDir = currentWorkingDir + commandLine = split("\\s".toRegex()) + standardOutput = byteOut + } + return String(byteOut.toByteArray()).trim() +} + +val gitCommitCount = "git rev-list HEAD --count".execute().toInt() + android { namespace = "io.github.a13e300.ksuwebui" compileSdk = 35 @@ -32,7 +45,7 @@ android { applicationId = "io.github.a13e300.ksuwebui" minSdk = 26 targetSdk = 35 - versionCode = 1 + versionCode = gitCommitCount versionName = "1.0" setProperty("archivesBaseName", "KsuWebUI-$versionName-$versionCode") }