From 29616b1cf715915ba45abb895935d868788b6056 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 2 Jan 2025 11:46:41 +0530 Subject: [PATCH] Fixed: Reproducible Builds. * To generate the APK for a specific date, set the "RELEASE_DATE" environment variable in the format `YYYY-MM-DD`. The APK will be generated for the specified date. If the variable is not set, the APK will be generated for the current date. --- buildSrc/src/main/kotlin/VersionCodeGenerator.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/VersionCodeGenerator.kt b/buildSrc/src/main/kotlin/VersionCodeGenerator.kt index 269b31198..aa5355415 100644 --- a/buildSrc/src/main/kotlin/VersionCodeGenerator.kt +++ b/buildSrc/src/main/kotlin/VersionCodeGenerator.kt @@ -23,9 +23,18 @@ fun String.getVersionCode(): Int { // the date when the automatic version code generation started val lastDate = LocalDate.of(2024, 7, 17) + // Get the current date. If the "RELEASE_DATE" environment variable is set(in YYYY-MM-DD format). + // it uses the specified date to generate the APK version code. + // Otherwise, it generates the version code based on the current date. + // See https://github.com/kiwix/kiwix-android/issues/4120 for more details. + val currentDate = if (!System.getenv("RELEASE_DATE").isNullOrEmpty()) { + LocalDate.parse(System.getenv("RELEASE_DATE")) + } else { + LocalDate.now() + } // Calculate the number of days between the lastDate and today's date. // This gives us the total number of days since the last version code was set. - val daysDifference = ChronoUnit.DAYS.between(lastDate, LocalDate.now()).toInt() + val daysDifference = ChronoUnit.DAYS.between(lastDate, currentDate).toInt() // Base version code. This is the version code of the last release uploaded to the Play Store. // We use this as the starting point for generating new version codes automatically.