Add release candidate number to version code

This commit is contained in:
Niels van Velzen
2020-08-23 19:34:52 +02:00
parent f3ab6775b0
commit af5751d3d8
3 changed files with 39 additions and 19 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ android {
applicationId = "org.jellyfin.mobile"
minSdkVersion(21)
targetSdkVersion(30)
versionName = "2.0.0-rc2"
versionName = "2.0.0-rc.2"
versionCode = getVersionCode(versionName)
setProperty("archivesBaseName", "jellyfin-android-v$versionName")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
+37 -15
View File
@@ -1,29 +1,51 @@
/**
* Get the versionCode for a given semver
* Get the version code for a given semantic version.
* Does not validate the input and thus will throw an exception when parts are missing.
*
* The pre-release part ("-rc.1", "-beta.1" etc.) defaults to 99
*
* Sample output:
* 0.0.0 -> 0
* 1.1.1 -> 10101
* 0.7.0 -> 700
* 99.99.99 -> 999999
*
* @return the versionCode, or null if value is invalid.
* MA.MI.PA-PR -> MAMIPAPR
* 0.0.0 -> 99
* 1.1.1 -> 1010199
* 0.7.0 -> 70099
* 99.99.99 -> 99999999
* 2.0.0-rc.3 -> 2000003
* 2.0.0 -> 2000099
* 99.99.99-rc.1 -> 99999901
*/
fun getVersionCode(versionName: String): Int? {
val parts = versionName
.substringBefore('-')
// Split to core and pre release parts with a default for pre release (null)
val (versionCore, versionPreRelease) = versionName
.split("-", limit = 2)
.let {
when (it.size) {
// No pre release part included
1 -> arrayOf(it[0], null)
// Pre release part included
else -> arrayOf(it[0], it[1])
}
}
// Parse core part
val (major, minor, patch) = versionCore!!
.splitToSequence('.')
.mapNotNull(String::toIntOrNull)
.take(3)
.toList()
// Not a valid semver
if (parts.size != 3) return null
// Parse pre release part (ignore type, only get the number)
val buildVersion = versionPreRelease
?.split('.', limit = 2)
?.getOrNull(1)
?.let(String::toIntOrNull)
// Build code
var code = 0
code += parts[0] * 10000 // Major (0-99)
code += parts[1] * 100 // Minor (0-99)
code += parts[2] // Patch (0-99)
code += major * 1000000 // Major (0-99)
code += minor * 10000 // Minor (0-99)
code += patch * 100 // Patch (0-99)
code += buildVersion ?: 99 // Pre release (0-99)
return code
}
}
+1 -3
View File
@@ -1,7 +1,5 @@
include(":app")
rootProject.name = "Jellyfin"
pluginManagement {
val kotlinVersion: String by settings
resolutionStrategy {
@@ -10,4 +8,4 @@ pluginManagement {
useVersion(kotlinVersion)
}
}
}
}