CalVer: use 2 digits for the year and 2 digits for the month.
This commit is contained in:
parent
0b04e40e1e
commit
e5aecbbf8d
2 changed files with 22 additions and 14 deletions
|
|
@ -18,21 +18,26 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion
|
||||||
* output.versionCode.set((output.versionCode.get() ?: 0) * 10 + abiCode))
|
* 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:
|
* 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 month
|
||||||
* - 2 digits for the release number
|
* - 1 (or 2) digits for the release number
|
||||||
* So for instance, the first release of Jan 2025 will have the version code: 20250100 (20_250_100)
|
* 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
|
private const val versionMonth = 1
|
||||||
|
|
||||||
// Note: must be in [0,99]
|
// Note: must be in [0,99]
|
||||||
private const val versionReleaseNumber = 0
|
private const val versionReleaseNumber = 0
|
||||||
|
|
||||||
object Versions {
|
object Versions {
|
||||||
const val VERSION_CODE = versionYear * 10_000 + versionMonth * 100 + versionReleaseNumber
|
const val VERSION_CODE = (2000 + versionYear) * 10_000 + versionMonth * 100 + versionReleaseNumber
|
||||||
const val VERSION_NAME = "$versionYear.$versionMonth.$versionReleaseNumber"
|
val VERSION_NAME = "$versionYear.${versionMonth.toString().padStart(2, '0')}.$versionReleaseNumber"
|
||||||
|
|
||||||
const val COMPILE_SDK = 35
|
const val COMPILE_SDK = 35
|
||||||
const val TARGET_SDK = 35
|
const val TARGET_SDK = 35
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,24 +94,28 @@ git pull
|
||||||
printf "\n================================================================================\n"
|
printf "\n================================================================================\n"
|
||||||
# Guessing version to propose a default version
|
# Guessing version to propose a default version
|
||||||
versionsFile="./plugins/src/main/kotlin/Versions.kt"
|
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)
|
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)
|
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 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))
|
versionReleaseNumberCandidate=$((currentVersionReleaseNumber + 1))
|
||||||
else
|
else
|
||||||
versionReleaseNumberCandidate=0
|
versionReleaseNumberCandidate=0
|
||||||
fi
|
fi
|
||||||
versionCandidate="${versionYearCandidate}.${versionMonthCandidate}.${versionReleaseNumberCandidate}"
|
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}}
|
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)
|
versionYear=$(echo "${version}" | cut -d "." -f1)
|
||||||
versionMonth=$(echo "${version}" | cut -d "." -f2)
|
versionMonth=$(echo "${version}" | cut -d "." -f2)
|
||||||
|
versionMonthNoLeadingZero=$(echo ${versionMonth} | sed 's/^0//')
|
||||||
versionReleaseNumber=$(echo "${version}" | cut -d "." -f3)
|
versionReleaseNumber=$(echo "${version}" | cut -d "." -f3)
|
||||||
|
|
||||||
printf "\n================================================================================\n"
|
printf "\n================================================================================\n"
|
||||||
|
|
@ -129,7 +133,7 @@ fi
|
||||||
versionsFileBak="${versionsFile}.bak"
|
versionsFileBak="${versionsFile}.bak"
|
||||||
cp ${versionsFile} ${versionsFileBak}
|
cp ${versionsFile} ${versionsFileBak}
|
||||||
sed "s/private const val versionYear = .*/private const val versionYear = ${versionYear}/" ${versionsFileBak} > ${versionsFile}
|
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}
|
sed "s/private const val versionReleaseNumber = .*/private const val versionReleaseNumber = ${versionReleaseNumber}/" ${versionsFileBak} > ${versionsFile}
|
||||||
rm ${versionsFileBak}
|
rm ${versionsFileBak}
|
||||||
|
|
||||||
|
|
@ -137,9 +141,8 @@ git commit -a -m "Setting version for the release ${version}"
|
||||||
|
|
||||||
printf "\n================================================================================\n"
|
printf "\n================================================================================\n"
|
||||||
printf "Creating fastlane file...\n"
|
printf "Creating fastlane file...\n"
|
||||||
printf -v versionMonth2Digits "%02d" "${versionMonth}"
|
|
||||||
printf -v versionReleaseNumber2Digits "%02d" "${versionReleaseNumber}"
|
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}"
|
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}"
|
printf "Main changes in this version: TODO.\nFull changelog: https://github.com/element-hq/element-x-android/releases" > "${fastlanePathFile}"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue