Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CalVer: use 2 digits for the year and 2 digits for the month. #4192

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions plugins/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 11 additions & 8 deletions tools/release/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -129,17 +133,16 @@ 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}

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}"

Expand Down
Loading