Skip to content

Commit

Permalink
Introduced Automatic Versioning with Manual Control Over Major Versio…
Browse files Browse the repository at this point in the history
…ns (#318)

* Automate app versioning

* Update version name
  • Loading branch information
cristhianescobar authored Sep 27, 2024
1 parent 3358bb0 commit 61f80de
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
62 changes: 58 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,51 @@ sentry {
includeSourceContext.set(true)
telemetry.set(true)
}


/**
* Generates a version code based on the current date and time in the format `yyMMddHH`.
*
* The version code is an integer composed of:
* - `yy`: The last two digits of the current year.
* - `MM`: The current month.
* - `dd`: The current day of the month.
* - `HH`: The current hour (24-hour format).
*
* The function formats the current date and time using `SimpleDateFormat`,
* converts it into a string, and then parses it as an integer.
*
* @return An integer representing the current date and time in the format `yyMMddHH`.
*/
fun getCurrentDateTimeVersionCode(): Int {
val dateFormat = SimpleDateFormat("yyMMddHH")
return dateFormat.format(Date()).toInt()
}

/**
* Generates a custom version name based on the provided major version and the current date and time.
*
* The version name follows the format: `major.YYYY.MMDDHHmm`, where:
* - `major`: The major version number passed as a parameter.
* - `YYYY`: The current year.
* - `MMDD`: The current month and day.
* - `HHmm`: The current hour and minute.
*
* The function retrieves the current date and time using `SimpleDateFormat` to format each component.
*
* @param major The major version number to be used as the first part of the version name.
* @return A custom version name string in the format: `major.YYYY.MMDDHHmm`.
*/
fun getCustomVersionName(major: Int): String {
val yearFormat = SimpleDateFormat("yyyy")
val monthDayFormat = SimpleDateFormat("MMdd")
val hourFormat = SimpleDateFormat("HH")
val minuteFormat = SimpleDateFormat("mm")

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

return "$major.$year.$monthDay$hour$minute"
}
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 61f80de

Please sign in to comment.