diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt index d244c0f8806b..a62baa21150e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/update/CustomGithubReleaseUpdateSource.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.features.misc.update +import at.hannibal2.skyhanni.utils.system.ModVersion import at.hannibal2.skyhanni.utils.system.PlatformUtils import com.google.gson.JsonPrimitive import moe.nea.libautoupdate.GithubReleaseUpdateData @@ -11,6 +12,11 @@ import moe.nea.libautoupdate.UpdateData */ class CustomGithubReleaseUpdateSource(owner: String, repository: String) : GithubReleaseUpdateSource(owner, repository) { + override fun findLatestRelease(validReleases: Iterable): UpdateData { + return validReleases.asSequence().maxBy { ModVersion.fromString(it.tagName) }.let { findAsset(it) } + ?: throw IllegalStateException("No valid release found") + } + override fun findAsset(release: GithubRelease?): UpdateData? { release ?: return null diff --git a/src/main/java/at/hannibal2/skyhanni/utils/system/ModVersion.kt b/src/main/java/at/hannibal2/skyhanni/utils/system/ModVersion.kt index 8276afd9c3c1..0643be002d12 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/system/ModVersion.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/system/ModVersion.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.utils.system data class ModVersion(val stable: Int, val beta: Int, val bugfix: Int) : Comparable { val isBeta get() = beta != 0 + val isBackport get() = beta == 0 && bugfix != 0 inline val asString get() = toString() diff --git a/src/test/java/at/hannibal2/skyhanni/test/UpdateVersionTest.kt b/src/test/java/at/hannibal2/skyhanni/test/UpdateVersionTest.kt new file mode 100644 index 000000000000..3a108d15d328 --- /dev/null +++ b/src/test/java/at/hannibal2/skyhanni/test/UpdateVersionTest.kt @@ -0,0 +1,28 @@ +package at.hannibal2.skyhanni.test + +import at.hannibal2.skyhanni.utils.system.ModVersion +import org.junit.jupiter.api.Test + +class UpdateVersionTest { + + private val versionA = ModVersion.fromString("1.0.0") + private val versionB = ModVersion.fromString("1.0.1") + private val versionC = ModVersion.fromString("1.0.2") + private val versionD = ModVersion.fromString("1.1.0") + private val versionE = ModVersion.fromString("1.2.0") + private val versionF = ModVersion.fromString("2.0.0") + + /** + * These tests assume you are on the beta updater branch (so you always want the most recent beta + */ + @Test + fun `test versions are correctly compared`() { + assert(versionA < versionB) + assert(versionB < versionC) + + assert(versionC < versionD) + assert(versionD < versionE) + + assert(versionE < versionF) + } +}