Skip to content

Impl: test minimum supported Coder version #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/kotlin/com/coder/gateway/CoderSupportedVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import org.jetbrains.annotations.PropertyKey
private const val BUNDLE = "version.CoderSupportedVersions"

object CoderSupportedVersions : DynamicBundle(BUNDLE) {
val lastTestedVersion = CoderSemVer.parse(message("lastTestedCoderVersion"))
val minCompatibleCoderVersion = CoderSemVer.parse(message("minCompatibleCoderVersion"))
val maxCompatibleCoderVersion = CoderSemVer.parse(message("maxCompatibleCoderVersion"))

@Suppress("SpreadOperator")
@JvmStatic
@Suppress("SpreadOperator")
private fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = getMessage(key, *params)
}
}
30 changes: 19 additions & 11 deletions src/main/kotlin/com/coder/gateway/sdk/CoderSemVer.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.coder.gateway.sdk


class CoderSemVer(private val major: Long = 0, private val minor: Long = 0) {
class CoderSemVer(private val major: Long = 0, private val minor: Long = 0, private val patch: Long = 0) : Comparable<CoderSemVer> {

init {
require(major >= 0) { "Coder major version must be a positive number" }
require(minor >= 0) { "Coder minor version must be a positive number" }
require(patch >= 0) { "Coder minor version must be a positive number" }
}

fun isCompatibleWith(other: CoderSemVer): Boolean {
// in the initial development phase minor changes when there are API incompatibilities
if (this.major == 0L) {
if (other.major > 0) return false
return this.minor == other.minor
}
return this.major <= other.major
fun isInClosedRange(start: CoderSemVer, endInclusive: CoderSemVer) = this in start..endInclusive


override fun toString(): String {
return "CoderSemVer(major=$major, minor=$minor)"
}

override fun equals(other: Any?): Boolean {
Expand All @@ -25,20 +24,28 @@ class CoderSemVer(private val major: Long = 0, private val minor: Long = 0) {

if (major != other.major) return false
if (minor != other.minor) return false
if (patch != other.patch) return false

return true
}

override fun hashCode(): Int {
var result = major.hashCode()
result = 31 * result + minor.hashCode()
result = 31 * result + patch.hashCode()
return result
}

override fun toString(): String {
return "CoderSemVer(major=$major, minor=$minor)"
}
override fun compareTo(other: CoderSemVer): Int {
if (major > other.major) return 1
if (major < other.major) return -1
if (minor > other.minor) return 1
if (minor < other.minor) return -1
if (patch > other.patch) return 1
if (patch < other.patch) return -1

return 0
}

companion object {
private val pattern = """^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$""".toRegex()
Expand All @@ -52,6 +59,7 @@ class CoderSemVer(private val major: Long = 0, private val minor: Long = 0) {
return CoderSemVer(
if (matchResult.groupValues[1].isNotEmpty()) matchResult.groupValues[1].toLong() else 0,
if (matchResult.groupValues[2].isNotEmpty()) matchResult.groupValues[2].toLong() else 0,
if (matchResult.groupValues[3].isNotEmpty()) matchResult.groupValues[3].toLong() else 0,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
}
} else {
val coderVersion = CoderSemVer.parse(coderClient.buildVersion)
val testedCoderVersion = CoderSupportedVersions.lastTestedVersion

if (!testedCoderVersion.isCompatibleWith(coderVersion)) {
if (!coderVersion.isInClosedRange(CoderSupportedVersions.minCompatibleCoderVersion, CoderSupportedVersions.maxCompatibleCoderVersion)) {
notificationBanner.apply {
component.isVisible = true
showWarning(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.unsupported.coder.version", coderClient.buildVersion))
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/version/CoderSupportedVersions.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lastTestedCoderVersion=0.13.0
minCompatibleCoderVersion=0.12.9
maxCompatibleCoderVersion=0.13.1
Loading