From e5aecbbf8dcc8897aec0a54d585a60eb4e482091 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 23 Jan 2025 18:28:33 +0100 Subject: [PATCH] CalVer: use 2 digits for the year and 2 digits for the month. --- plugins/src/main/kotlin/Versions.kt | 17 +++++++++++------ tools/release/release.sh | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/plugins/src/main/kotlin/Versions.kt b/plugins/src/main/kotlin/Versions.kt index a9902cd3ac2..62ff3293118 100644 --- a/plugins/src/main/kotlin/Versions.kt +++ b/plugins/src/main/kotlin/Versions.kt @@ -18,21 +18,26 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion * output.versionCode.set((output.versionCode.get() ?: 0) * 10 + abiCode)) * ``` * We are using a CalVer-like approach to version the application. The version code is calculated as follows: - * - 4 digits for the year + * - 2 digits for the year * - 2 digits for the month - * - 2 digits for the release number - * So for instance, the first release of Jan 2025 will have the version code: 20250100 (20_250_100) + * - 1 (or 2) digits for the release number + * Note that the version codes need to be greater than the ones calculated for the previous releases, so we use + * year on 4 digits for this internal value. + * So for instance, the first release of Jan 2025 will have: + * - the version name: 25.01.0 + * - the version code: 20250100a (202_501_00a) where `a` stands for the architecture code */ -private const val versionYear = 2025 +private const val versionYear = 25 private const val versionMonth = 1 // Note: must be in [0,99] private const val versionReleaseNumber = 0 object Versions { - const val VERSION_CODE = versionYear * 10_000 + versionMonth * 100 + versionReleaseNumber - const val VERSION_NAME = "$versionYear.$versionMonth.$versionReleaseNumber" + const val VERSION_CODE = (2000 + versionYear) * 10_000 + versionMonth * 100 + versionReleaseNumber + val VERSION_NAME = "$versionYear.${versionMonth.toString().padStart(2, '0')}.$versionReleaseNumber" + const val COMPILE_SDK = 35 const val TARGET_SDK = 35 diff --git a/tools/release/release.sh b/tools/release/release.sh index 1bd8dd60535..735c57503ef 100755 --- a/tools/release/release.sh +++ b/tools/release/release.sh @@ -94,24 +94,28 @@ git pull printf "\n================================================================================\n" # Guessing version to propose a default version versionsFile="./plugins/src/main/kotlin/Versions.kt" -versionYearCandidate=$(date +%Y) +# Get current year on 2 digits +versionYearCandidate=$(date +%y) currentVersionMonth=$(grep "val versionMonth" ${versionsFile} | cut -d " " -f6) -versionMonthCandidate=$(date +%-m) +# Get current month on 2 digits +versionMonthCandidate=$(date +%m) +versionMonthCandidateNoLeadingZero=$(echo ${versionMonthCandidate} | sed 's/^0//') currentVersionReleaseNumber=$(grep "val versionReleaseNumber" ${versionsFile} | cut -d " " -f6) # if the current month is the same as the current version, we increment the release number, else we reset it to 0 -if [[ ${currentVersionMonth} -eq ${versionMonthCandidate} ]]; then +if [[ ${currentVersionMonth} -eq ${versionMonthCandidateNoLeadingZero} ]]; then versionReleaseNumberCandidate=$((currentVersionReleaseNumber + 1)) else versionReleaseNumberCandidate=0 fi versionCandidate="${versionYearCandidate}.${versionMonthCandidate}.${versionReleaseNumberCandidate}" -read -p "Please enter the release version (example: ${versionCandidate}). Just press enter if ${versionCandidate} is correct. " version +read -p "Please enter the release version (example: ${versionCandidate}). Format must be 'YY.MM.x' or 'YY.MM.xy'. Just press enter if ${versionCandidate} is correct. " version version=${version:-${versionCandidate}} -# extract major, minor and patch for future use +# extract year, month and release number for future use versionYear=$(echo "${version}" | cut -d "." -f1) versionMonth=$(echo "${version}" | cut -d "." -f2) +versionMonthNoLeadingZero=$(echo ${versionMonth} | sed 's/^0//') versionReleaseNumber=$(echo "${version}" | cut -d "." -f3) printf "\n================================================================================\n" @@ -129,7 +133,7 @@ fi versionsFileBak="${versionsFile}.bak" cp ${versionsFile} ${versionsFileBak} sed "s/private const val versionYear = .*/private const val versionYear = ${versionYear}/" ${versionsFileBak} > ${versionsFile} -sed "s/private const val versionMonth = .*/private const val versionMonth = ${versionMonth}/" ${versionsFile} > ${versionsFileBak} +sed "s/private const val versionMonth = .*/private const val versionMonth = ${versionMonthNoLeadingZero}/" ${versionsFile} > ${versionsFileBak} sed "s/private const val versionReleaseNumber = .*/private const val versionReleaseNumber = ${versionReleaseNumber}/" ${versionsFileBak} > ${versionsFile} rm ${versionsFileBak} @@ -137,9 +141,8 @@ git commit -a -m "Setting version for the release ${version}" printf "\n================================================================================\n" printf "Creating fastlane file...\n" -printf -v versionMonth2Digits "%02d" "${versionMonth}" printf -v versionReleaseNumber2Digits "%02d" "${versionReleaseNumber}" -fastlaneFile="${versionYear}${versionMonth2Digits}${versionReleaseNumber2Digits}0.txt" +fastlaneFile="20${versionYear}${versionMonth}${versionReleaseNumber2Digits}0.txt" fastlanePathFile="./fastlane/metadata/android/en-US/changelogs/${fastlaneFile}" printf "Main changes in this version: TODO.\nFull changelog: https://github.com/element-hq/element-x-android/releases" > "${fastlanePathFile}"