Skip to content

Commit 51bf92e

Browse files
authored
Merge pull request coder#118 from coder/impl-test-min-support-for-coder
Impl: test minimum supported Coder version
2 parents 25421bb + 24b00be commit 51bf92e

File tree

5 files changed

+193
-110
lines changed

5 files changed

+193
-110
lines changed

src/main/kotlin/com/coder/gateway/CoderSupportedVersions.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import org.jetbrains.annotations.PropertyKey
99
private const val BUNDLE = "version.CoderSupportedVersions"
1010

1111
object CoderSupportedVersions : DynamicBundle(BUNDLE) {
12-
val lastTestedVersion = CoderSemVer.parse(message("lastTestedCoderVersion"))
12+
val minCompatibleCoderVersion = CoderSemVer.parse(message("minCompatibleCoderVersion"))
13+
val maxCompatibleCoderVersion = CoderSemVer.parse(message("maxCompatibleCoderVersion"))
1314

14-
@Suppress("SpreadOperator")
1515
@JvmStatic
16+
@Suppress("SpreadOperator")
1617
private fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = getMessage(key, *params)
17-
}
18+
}

src/main/kotlin/com/coder/gateway/sdk/CoderSemVer.kt

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.coder.gateway.sdk
22

33

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

66
init {
77
require(major >= 0) { "Coder major version must be a positive number" }
88
require(minor >= 0) { "Coder minor version must be a positive number" }
9+
require(patch >= 0) { "Coder minor version must be a positive number" }
910
}
1011

11-
fun isCompatibleWith(other: CoderSemVer): Boolean {
12-
// in the initial development phase minor changes when there are API incompatibilities
13-
if (this.major == 0L) {
14-
if (other.major > 0) return false
15-
return this.minor == other.minor
16-
}
17-
return this.major <= other.major
12+
fun isInClosedRange(start: CoderSemVer, endInclusive: CoderSemVer) = this in start..endInclusive
13+
14+
15+
override fun toString(): String {
16+
return "CoderSemVer(major=$major, minor=$minor)"
1817
}
1918

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

2625
if (major != other.major) return false
2726
if (minor != other.minor) return false
27+
if (patch != other.patch) return false
2828

2929
return true
3030
}
3131

3232
override fun hashCode(): Int {
3333
var result = major.hashCode()
3434
result = 31 * result + minor.hashCode()
35+
result = 31 * result + patch.hashCode()
3536
return result
3637
}
3738

38-
override fun toString(): String {
39-
return "CoderSemVer(major=$major, minor=$minor)"
40-
}
39+
override fun compareTo(other: CoderSemVer): Int {
40+
if (major > other.major) return 1
41+
if (major < other.major) return -1
42+
if (minor > other.minor) return 1
43+
if (minor < other.minor) return -1
44+
if (patch > other.patch) return 1
45+
if (patch < other.patch) return -1
4146

47+
return 0
48+
}
4249

4350
companion object {
4451
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()
@@ -52,6 +59,7 @@ class CoderSemVer(private val major: Long = 0, private val minor: Long = 0) {
5259
return CoderSemVer(
5360
if (matchResult.groupValues[1].isNotEmpty()) matchResult.groupValues[1].toLong() else 0,
5461
if (matchResult.groupValues[2].isNotEmpty()) matchResult.groupValues[2].toLong() else 0,
62+
if (matchResult.groupValues[3].isNotEmpty()) matchResult.groupValues[3].toLong() else 0,
5563
)
5664
}
5765
}

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
325325
}
326326
} else {
327327
val coderVersion = CoderSemVer.parse(coderClient.buildVersion)
328-
val testedCoderVersion = CoderSupportedVersions.lastTestedVersion
329-
330-
if (!testedCoderVersion.isCompatibleWith(coderVersion)) {
328+
if (!coderVersion.isInClosedRange(CoderSupportedVersions.minCompatibleCoderVersion, CoderSupportedVersions.maxCompatibleCoderVersion)) {
331329
notificationBanner.apply {
332330
component.isVisible = true
333331
showWarning(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.unsupported.coder.version", coderClient.buildVersion))
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
lastTestedCoderVersion=0.13.0
1+
minCompatibleCoderVersion=0.12.9
2+
maxCompatibleCoderVersion=0.13.1

0 commit comments

Comments
 (0)