Skip to content

Commit

Permalink
Automate app versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
cristhianescobar committed Sep 25, 2024
1 parent bb785be commit 3cee750
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
56 changes: 52 additions & 4 deletions android/app-newm/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import java.text.SimpleDateFormat
import java.util.Date

apply(from = "../../gradle_include/compose.gradle")
apply(from = "../../gradle_include/circuit.gradle")
apply(from = "../../gradle_include/flipper.gradle")

plugins {
id("com.android.application")
id( "com.google.gms.google-services")
id("com.google.gms.google-services")
id("kotlin-parcelize")
kotlin("android")
kotlin("kapt")
Expand All @@ -23,8 +25,8 @@ android {
applicationId = "io.newm"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 5
versionName = "0.3.0"
versionCode = getCurrentDateTimeVersionCode()
versionName = getCustomVersionName(major = 1)
testInstrumentationRunner = "io.newm.NewmAndroidJUnitRunner"
testApplicationId = "io.newm.test"
}
Expand Down Expand Up @@ -60,7 +62,11 @@ android {
dimension = "version"
}
all {
resValue("string", "account_type", "$applicationId${applicationIdSuffix.orEmpty()}.account")
resValue(
"string",
"account_type",
"$applicationId${applicationIdSuffix.orEmpty()}.account"
)
}
}

Expand Down Expand Up @@ -124,3 +130,45 @@ sentry {
includeSourceContext.set(true)
telemetry.set(true)
}

/**
* Generates a dynamic `versionCode` based on the current date and hour.
*
* The `versionCode` is constructed using the format `yyyyMMddHH`, which represents:
* - `yyyy`: 4-digit year
* - `MM`: 2-digit month (01-12)
* - `dd`: 2-digit day of the month (01-31)
* - `HH`: 2-digit hour in 24-hour format (00-23)
*
* This ensures that each build has a unique `versionCode` per hour of the day.
*
* @return An integer representing the dynamically generated `versionCode`.
*/
fun getCurrentDateTimeVersionCode(): Int {
val dateFormat = SimpleDateFormat("yyyyMMddHH")
return dateFormat.format(Date()).toInt()
}

/**
* Generates a dynamic `versionName` based on a specified major version, current year, month, day, and hour.
*
* The `versionName` follows the format `Major.Year.MMDDHH`, where:
* - `Major`: The major version number provided as an input parameter.
* - `Year`: The current year (e.g., 2024).
* - `MMDD`: Month and day combined (e.g., 0925 for September 25).
* - `HH`: Hour in 24-hour format (00-23).
*
* @param major The major version number to be included in the `versionName`.
* @return A string representing the dynamically generated `versionName`.
*/
fun getCustomVersionName(major: Int): String {
val yearFormat = SimpleDateFormat("yyyy")
val monthDayFormat = SimpleDateFormat("MMdd")
val hourFormat = SimpleDateFormat("HH")

val year = yearFormat.format(Date())
val monthDay = monthDayFormat.format(Date())
val hour = hourFormat.format(Date())

return "$major.$year.$monthDay$hour"
}
1 change: 0 additions & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ buildConfig {
buildConfigField<String>("GOOGLE_AUTH_CLIENT_ID", properties.getProperty("GOOGLE_AUTH_CLIENT_ID").replace("\"", ""))
buildConfigField<String>("RECAPTCHA_SITE_KEY", properties.getProperty("RECAPTCHA_SITE_KEY").replace("\"", ""))
buildConfigField<String>("SENTRY_AUTH_TOKEN", properties.getProperty("SENTRY_AUTH_TOKEN").replace("\"", ""))
buildConfigField<String>("NEWM_MOBILE_APP_VERSION", "0.0.0")
buildConfigField<String>("ANDROID_SENTRY_DSN", properties.getProperty("ANDROID_SENTRY_DSN").replace("\"", ""))
}

Expand Down

0 comments on commit 3cee750

Please sign in to comment.