Skip to content

Commit 3d26377

Browse files
authored
Merge pull request #5318 from element-hq/feature/bma/releaseScriptImprovement
Improve release script and the file Versions.kt
2 parents 7e0931c + 7fcc090 commit 3d26377

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

plugins/src/main/kotlin/Versions.kt

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion
1313
* Max versionCode allowed by the PlayStore (for information):
1414
* 2_100_000_000
1515
*
16-
* Also note that the versionCode is multiplied by 10 in app/build.gradle.kts#L168:
16+
* Also note that the versionCode is multiplied by 10 in app/build.gradle.kts:
1717
* ```
18-
* output.versionCode.set((output.versionCode.get() ?: 0) * 10 + abiCode))
18+
* output.versionCode.set((output.versionCode.orNull ?: 0) * 10 + abiCode)
1919
* ```
2020
* We are using a CalVer-like approach to version the application. The version code is calculated as follows:
2121
* - 2 digits for the year
@@ -28,27 +28,80 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion
2828
* - the version code: 20250100a (202_501_00a) where `a` stands for the architecture code
2929
*/
3030

31+
/**
32+
* Year of the version on 2 digits.
33+
* Do not update this value. it is updated by the release script.
34+
*/
3135
private const val versionYear = 25
36+
37+
/**
38+
* Month of the version on 2 digits. Value must be in [1,12].
39+
* Do not update this value. it is updated by the release script.
40+
*/
3241
private const val versionMonth = 9
3342

34-
// Note: must be in [0,99]
43+
/**
44+
* Release number in the month. Value must be in [0,99].
45+
* Do not update this value. it is updated by the release script.
46+
*/
3547
private const val versionReleaseNumber = 1
3648

3749
object Versions {
50+
/**
51+
* Base version code that will be set in the Android Manifest.
52+
* The value will be modified at build time to add the ABI code when APK are build.
53+
* AAB will have a ABI code of 0.
54+
* See comment above for the calculation method.
55+
*/
3856
const val VERSION_CODE = (2000 + versionYear) * 10_000 + versionMonth * 100 + versionReleaseNumber
3957
val VERSION_NAME = "$versionYear.${versionMonth.toString().padStart(2, '0')}.$versionReleaseNumber"
4058

41-
// When updating COMPILE_SDK, please do not forget to update the value for `buildToolsVersion`
42-
// in the file `tools/release/release.sh`
59+
/**
60+
* Compile SDK version. Must be updated when a new Android version is released.
61+
* When updating COMPILE_SDK, please also update BUILD_TOOLS_VERSION.
62+
*/
4363
const val COMPILE_SDK = 36
64+
65+
/**
66+
* Build tools version. Must be kept in sync with COMPILE_SDK.
67+
* The value is used by the release script.
68+
*/
69+
@Suppress("unused")
70+
private const val BUILD_TOOLS_VERSION = "36.0.0"
71+
72+
/**
73+
* Target SDK version. Should be kept up to date with COMPILE_SDK.
74+
*/
4475
const val TARGET_SDK = 36
4576

46-
// When updating the `minSdk`, make sure to update the value of `minSdkVersion` in the file `tools/release/release.sh`
77+
/**
78+
* Minimum SDK version for FOSS builds.
79+
*/
4780
private const val MIN_SDK_FOSS = 24
81+
82+
/**
83+
* Minimum SDK version for Enterprise builds.
84+
*/
4885
private const val MIN_SDK_ENTERPRISE = 33
86+
87+
/**
88+
* minSdkVersion that will be set in the Android Manifest.
89+
*/
4990
val minSdk = if (isEnterpriseBuild) MIN_SDK_ENTERPRISE else MIN_SDK_FOSS
5091

92+
/**
93+
* Java version used for compilation.
94+
* Update this value when you want to use a newer Java version.
95+
*/
5196
private const val JAVA_VERSION = 21
97+
5298
val javaVersion: JavaVersion = JavaVersion.toVersion(JAVA_VERSION)
5399
val javaLanguageVersion: JavaLanguageVersion = JavaLanguageVersion.of(JAVA_VERSION)
100+
101+
// Perform some checks on the values to avoid releasing with bad values
102+
init {
103+
require(versionMonth in 1..12) { "versionMonth must be in [1,12]" }
104+
require(versionReleaseNumber in 0..99) { "versionReleaseNumber must be in [0,99]" }
105+
require(BUILD_TOOLS_VERSION.startsWith(COMPILE_SDK.toString())) { "When updating COMPILE_SDK, please also update BUILD_TOOLS_VERSION" }
106+
}
54107
}

tools/release/release.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ fi
6464

6565
# Read minSdkVersion from file plugins/src/main/kotlin/Versions.kt
6666
minSdkVersion=$(grep "MIN_SDK_FOSS =" ./plugins/src/main/kotlin/Versions.kt |cut -d '=' -f 2 |xargs)
67-
buildToolsVersion="36.0.0"
67+
# Read buildToolsVersion from file plugins/src/main/kotlin/Versions.kt
68+
buildToolsVersion=$(grep "BUILD_TOOLS_VERSION =" ./plugins/src/main/kotlin/Versions.kt |cut -d '=' -f 2 |xargs)
6869
buildToolsPath="${androidHome}/build-tools/${buildToolsVersion}"
6970

7071
if [[ ! -d ${buildToolsPath} ]]; then

0 commit comments

Comments
 (0)