Merge pull request #40 from nielsvanvelzen/rcversioncode

Add release candidate number to version code
This commit is contained in:
Max Rumpf
2020-08-23 21:30:14 +02:00
committed by GitHub
3 changed files with 36 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"
+34 -15
View File
@@ -1,29 +1,48 @@
/**
* 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) =
when (val index = versionName.indexOf('-')) {
// No pre-release part included
-1 -> versionName to null
// Pre-release part included
else -> versionName.substring(0, index) to
versionName.substring(index + 1, versionName.length)
}
// 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
?.substringAfter('.')
?.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)
}
}
}
}