manager: Add git commit to version
This commit is contained in:
@@ -2,6 +2,7 @@ import com.android.build.api.dsl.ApplicationExtension
|
|||||||
import com.android.build.gradle.BaseExtension
|
import com.android.build.gradle.BaseExtension
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import org.jetbrains.kotlin.konan.properties.Properties
|
import org.jetbrains.kotlin.konan.properties.Properties
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application") apply false
|
id("com.android.application") apply false
|
||||||
@@ -25,13 +26,41 @@ val androidCompileSdk = 33
|
|||||||
val androidBuildToolsVersion = "33.0.1"
|
val androidBuildToolsVersion = "33.0.1"
|
||||||
val androidSourceCompatibility = JavaVersion.VERSION_11
|
val androidSourceCompatibility = JavaVersion.VERSION_11
|
||||||
val androidTargetCompatibility = JavaVersion.VERSION_11
|
val androidTargetCompatibility = JavaVersion.VERSION_11
|
||||||
val managerVersionCode = 10302
|
val managerVersionCode = getVersionCode()
|
||||||
val managerVersionName = "0.3.2"
|
val managerVersionName = getVersionName()
|
||||||
|
|
||||||
tasks.register<Delete>("clean") {
|
tasks.register<Delete>("clean") {
|
||||||
delete(rootProject.buildDir)
|
delete(rootProject.buildDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getGitCommitCount(): Int {
|
||||||
|
val out = ByteArrayOutputStream()
|
||||||
|
exec {
|
||||||
|
commandLine("git", "rev-list", "--count", "HEAD")
|
||||||
|
standardOutput = out
|
||||||
|
}
|
||||||
|
return out.toString().trim().toInt()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getGitDescribe(): String {
|
||||||
|
val out = ByteArrayOutputStream()
|
||||||
|
exec {
|
||||||
|
commandLine("git", "describe", "--tags", "--always")
|
||||||
|
standardOutput = out
|
||||||
|
}
|
||||||
|
return out.toString().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getVersionCode(): Int {
|
||||||
|
val commitCount = getGitCommitCount()
|
||||||
|
val major = 1
|
||||||
|
return major * 10000 + commitCount
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getVersionName(): String {
|
||||||
|
return getGitDescribe()
|
||||||
|
}
|
||||||
|
|
||||||
fun Project.configureBaseExtension() {
|
fun Project.configureBaseExtension() {
|
||||||
extensions.findByType<BaseExtension>()?.run {
|
extensions.findByType<BaseExtension>()?.run {
|
||||||
compileSdkVersion(androidCompileSdk)
|
compileSdkVersion(androidCompileSdk)
|
||||||
|
|||||||
Reference in New Issue
Block a user