From 45e63e9910e7137006e3784fd13a0bd6571c2d82 Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Sun, 28 Jul 2024 03:27:12 -0400 Subject: [PATCH] fix versioning (#280) --- app/build.gradle.kts | 16 +++++++--------- buildSrc/src/main/kotlin/Extensions.kt | 21 ++++++++++++--------- logcatter/build.gradle.kts | 4 ++-- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c2fdc7c..a3c5bfe 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,8 +20,8 @@ android { applicationId = Constants.APP_ID minSdk = Constants.MIN_SDK targetSdk = Constants.TARGET_SDK - versionCode = Constants.VERSION_CODE - versionName = Constants.VERSION_NAME + versionCode = determineVersionCode() + versionName = determineVersionName() ksp { arg("room.schemaLocation", "$projectDir/schemas") } @@ -56,14 +56,12 @@ android { getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro", ) - signingConfig = signingConfigs.getByName(Constants.RELEASE) + signingConfig = signingConfigs.getByName(Constants.DEBUG) } debug { isDebuggable = true } create(Constants.NIGHTLY) { initWith(buildTypes.getByName(Constants.RELEASE)) - defaultConfig.versionName = nightlyVersionName() - defaultConfig.versionCode = nightlyVersionCode() } applicationVariants.all { @@ -185,10 +183,10 @@ dependencies { implementation(libs.androidx.core.splashscreen) } -fun nightlyVersionCode(): Int { - return Constants.VERSION_CODE + Constants.NIGHTLY_CODE +fun determineVersionCode(): Int { + return if(isNightlyBuild()) Constants.VERSION_CODE + Constants.NIGHTLY_CODE else Constants.VERSION_CODE } -fun nightlyVersionName(): String { - return Constants.VERSION_NAME + "-${grgitService.service.get().grgit.head().abbreviatedId}" +fun determineVersionName(): String { + return if(isNightlyBuild()) Constants.VERSION_NAME + "-${grgitService.service.get().grgit.head().abbreviatedId}" else Constants.VERSION_NAME } diff --git a/buildSrc/src/main/kotlin/Extensions.kt b/buildSrc/src/main/kotlin/Extensions.kt index 9c2ba06..a2a476f 100644 --- a/buildSrc/src/main/kotlin/Extensions.kt +++ b/buildSrc/src/main/kotlin/Extensions.kt @@ -3,13 +3,13 @@ import org.gradle.api.invocation.Gradle import java.io.File import java.util.Properties -private fun getCurrentFlavor(gradle: Gradle): String { +fun Project.getCurrentFlavor(): String { val taskRequestsStr = gradle.startParameter.taskRequests.toString() val pattern: java.util.regex.Pattern = - if (taskRequestsStr.contains("assemble")) { - java.util.regex.Pattern.compile("assemble(\\w+)(Release|Debug)") + if (taskRequestsStr.contains(":app:assemble")) { + java.util.regex.Pattern.compile(":app:assemble(\\w+)(Release|Debug)") } 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) @@ -23,8 +23,15 @@ private fun getCurrentFlavor(gradle: Gradle): String { 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? { - val properties = java.util.Properties() + val properties = Properties() val localProperties = File(file) if (localProperties.isFile) { 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) } -fun Project.isGeneralFlavor(gradle: Gradle): Boolean { - return getCurrentFlavor(gradle) == "general" -} - fun Project.getSigningProperties(): Properties { return Properties().apply { diff --git a/logcatter/build.gradle.kts b/logcatter/build.gradle.kts index 0678d7e..0252ed2 100644 --- a/logcatter/build.gradle.kts +++ b/logcatter/build.gradle.kts @@ -23,8 +23,8 @@ android { ) } - create("nightly") { - initWith(getByName("release")) + create(Constants.NIGHTLY) { + initWith(getByName(Constants.RELEASE)) } } compileOptions {