fix versioning (#280)

This commit is contained in:
Zane Schepke 2024-07-28 03:27:12 -04:00 committed by GitHub
parent 66e89c83e2
commit 45e63e9910
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 20 deletions

View File

@ -20,8 +20,8 @@ android {
applicationId = Constants.APP_ID applicationId = Constants.APP_ID
minSdk = Constants.MIN_SDK minSdk = Constants.MIN_SDK
targetSdk = Constants.TARGET_SDK targetSdk = Constants.TARGET_SDK
versionCode = Constants.VERSION_CODE versionCode = determineVersionCode()
versionName = Constants.VERSION_NAME versionName = determineVersionName()
ksp { arg("room.schemaLocation", "$projectDir/schemas") } ksp { arg("room.schemaLocation", "$projectDir/schemas") }
@ -56,14 +56,12 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"), getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro", "proguard-rules.pro",
) )
signingConfig = signingConfigs.getByName(Constants.RELEASE) signingConfig = signingConfigs.getByName(Constants.DEBUG)
} }
debug { isDebuggable = true } debug { isDebuggable = true }
create(Constants.NIGHTLY) { create(Constants.NIGHTLY) {
initWith(buildTypes.getByName(Constants.RELEASE)) initWith(buildTypes.getByName(Constants.RELEASE))
defaultConfig.versionName = nightlyVersionName()
defaultConfig.versionCode = nightlyVersionCode()
} }
applicationVariants.all { applicationVariants.all {
@ -185,10 +183,10 @@ dependencies {
implementation(libs.androidx.core.splashscreen) implementation(libs.androidx.core.splashscreen)
} }
fun nightlyVersionCode(): Int { fun determineVersionCode(): Int {
return Constants.VERSION_CODE + Constants.NIGHTLY_CODE return if(isNightlyBuild()) Constants.VERSION_CODE + Constants.NIGHTLY_CODE else Constants.VERSION_CODE
} }
fun nightlyVersionName(): String { fun determineVersionName(): String {
return Constants.VERSION_NAME + "-${grgitService.service.get().grgit.head().abbreviatedId}" return if(isNightlyBuild()) Constants.VERSION_NAME + "-${grgitService.service.get().grgit.head().abbreviatedId}" else Constants.VERSION_NAME
} }

View File

@ -3,13 +3,13 @@ import org.gradle.api.invocation.Gradle
import java.io.File import java.io.File
import java.util.Properties import java.util.Properties
private fun getCurrentFlavor(gradle: Gradle): String { fun Project.getCurrentFlavor(): String {
val taskRequestsStr = gradle.startParameter.taskRequests.toString() val taskRequestsStr = gradle.startParameter.taskRequests.toString()
val pattern: java.util.regex.Pattern = val pattern: java.util.regex.Pattern =
if (taskRequestsStr.contains("assemble")) { if (taskRequestsStr.contains(":app:assemble")) {
java.util.regex.Pattern.compile("assemble(\\w+)(Release|Debug)") java.util.regex.Pattern.compile(":app:assemble(\\w+)(Release|Debug)")
} else { } else {
java.util.regex.Pattern.compile("bundle(\\w+)(Release|Debug)") java.util.regex.Pattern.compile(":app:bundle(\\w+)(Release|Debug)")
} }
val matcher = pattern.matcher(taskRequestsStr) val matcher = pattern.matcher(taskRequestsStr)
@ -23,8 +23,15 @@ private fun getCurrentFlavor(gradle: Gradle): String {
return flavor return flavor
} }
fun Project.isNightlyBuild(): Boolean {
val taskRequestsStr = gradle.startParameter.taskRequests[0].toString()
return taskRequestsStr.lowercase().contains(Constants.NIGHTLY).also {
project.logger.lifecycle("Nightly build: $it")
}
}
fun getLocalProperty(key: String, file: String = "local.properties"): String? { fun getLocalProperty(key: String, file: String = "local.properties"): String? {
val properties = java.util.Properties() val properties = Properties()
val localProperties = File(file) val localProperties = File(file)
if (localProperties.isFile) { if (localProperties.isFile) {
java.io.InputStreamReader(java.io.FileInputStream(localProperties), Charsets.UTF_8) java.io.InputStreamReader(java.io.FileInputStream(localProperties), Charsets.UTF_8)
@ -35,10 +42,6 @@ fun getLocalProperty(key: String, file: String = "local.properties"): String? {
return properties.getProperty(key) return properties.getProperty(key)
} }
fun Project.isGeneralFlavor(gradle: Gradle): Boolean {
return getCurrentFlavor(gradle) == "general"
}
fun Project.getSigningProperties(): Properties { fun Project.getSigningProperties(): Properties {
return Properties().apply { return Properties().apply {

View File

@ -23,8 +23,8 @@ android {
) )
} }
create("nightly") { create(Constants.NIGHTLY) {
initWith(getByName("release")) initWith(getByName(Constants.RELEASE))
} }
} }
compileOptions { compileOptions {