Skip to content

Commit

Permalink
mirrord binary download improvements (#180)
Browse files Browse the repository at this point in the history
* Remove quotes around GITHUB_PATH in e2e

* Changelog

* ..

* ..

* format

* changelog

* e2e

* ..

* format

* format

* ..
  • Loading branch information
infiniteregrets authored Nov 21, 2023
1 parent 7c4979c commit 88039fe
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/reusable_e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
if: ${{ inputs.mirrord_release_branch }}
run: |
chmod u+x mirrord
echo "${GITHUB_WORKSPACE}" >> "$GITHUB_PATH"
echo "${GITHUB_WORKSPACE}" >> $GITHUB_PATH
- name: get the latest mirrord binary
if: ${{ !inputs.mirrord_release_branch }}
Expand Down Expand Up @@ -112,7 +112,8 @@ jobs:
./gradlew test
- name: Save the failure video
if: ${{ failure() }}
continue-on-error: true
if: ${{ always() }}
run: |
mv video build/reports
- name: Save fails report
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+auto-update-and-ci.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove quotes around GITHUB_PATH in e2e and add "CI_BUILD_PLUGIN" check to e2e for releases
1 change: 1 addition & 0 deletions changelog.d/+provide-video.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Always provide video for CI run
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.metalbear.mirrord

import com.github.zafarkhaja.semver.Version
import com.intellij.execution.wsl.WSLDistribution
import com.intellij.notification.NotificationType
import com.intellij.openapi.components.Service
Expand Down Expand Up @@ -35,6 +36,7 @@ private const val DOWNLOAD_ENDPOINT = "https://github.com/metalbear-co/mirrord/r
class MirrordBinaryManager {
@Volatile
private var latestSupportedVersion: String? = null
private var downloadVersion: String? = null

/**
* Schedules the update task at project startup.
Expand Down Expand Up @@ -78,27 +80,29 @@ class MirrordBinaryManager {

val autoUpdate = MirrordSettingsState.instance.mirrordState.autoUpdate
val userSelectedMirrordVersion = MirrordSettingsState.instance.mirrordState.mirrordVersion
manager.latestSupportedVersion = manager.fetchLatestSupportedVersion(product, indicator)

val version = when {
// auto update -> false -> use mirrordVersion if it's not empty
!autoUpdate && userSelectedMirrordVersion.isNotEmpty() -> {
if (checkVersionFormat(userSelectedMirrordVersion)) {
userSelectedMirrordVersion
} else {
!autoUpdate && (userSelectedMirrordVersion.isNotEmpty()) -> {
try {
Version.valueOf(userSelectedMirrordVersion)
} catch (e: Exception) {
project
.service<MirrordProjectService>()
.notifier
.notification("mirrord version format is invalid!", NotificationType.WARNING)
.fire()
return
}
userSelectedMirrordVersion
}
// auto update -> false -> mirrordVersion is empty -> needs check in the path
// if not in path -> fetch latest version
!autoUpdate && userSelectedMirrordVersion.isEmpty() -> null

// auto update -> true -> fetch latest version
else -> manager.fetchLatestSupportedVersion(product, indicator)
else -> manager.latestSupportedVersion
}

val local = if (checkInPath) {
Expand All @@ -111,9 +115,9 @@ class MirrordBinaryManager {
return
}

manager.latestSupportedVersion = version
// auto update -> false -> mirrordVersion is empty -> no cli found locally -> fetch latest version
?: manager.fetchLatestSupportedVersion(product, indicator)
manager.downloadVersion = version
// auto update -> false -> mirrordVersion is empty -> no cli found locally -> latest version
?: manager.latestSupportedVersion

if (downloadInProgress.compareAndExchange(false, true)) {
return
Expand Down Expand Up @@ -148,14 +152,6 @@ class MirrordBinaryManager {
)
}
}

/**
* checks if the passed version string matches *.*.* format (numbers only)
* @param version version string to check
* */
fun checkVersionFormat(version: String): Boolean {
return version.matches(Regex("^[0-9]+\\.[0-9]+\\.[0-9]+$"))
}
}

private fun fetchLatestSupportedVersion(product: String?, indicator: ProgressIndicator): String {
Expand Down Expand Up @@ -192,7 +188,7 @@ class MirrordBinaryManager {
}

private fun updateBinary(indicator: ProgressIndicator) {
val version = latestSupportedVersion ?: return
val version = downloadVersion ?: return

val url = if (SystemInfo.isMac) {
"$DOWNLOAD_ENDPOINT/$version/mirrord_mac_universal"
Expand Down Expand Up @@ -283,7 +279,19 @@ class MirrordBinaryManager {
}

val binary = MirrordBinary(output, wslDistribution)
if (requiredVersion == null || requiredVersion == binary.version) {

val isRequiredVersion = try {
// for release CI, the tag can be greater than the latest release
if (System.getenv("CI_BUILD_PLUGIN") == "true") {
Version.valueOf(binary.version).greaterThanOrEqualTo(Version.valueOf(requiredVersion))
} else {
Version.valueOf(binary.version).equals(Version.valueOf(requiredVersion))
}
} catch (e: Exception) {
MirrordLogger.logger.debug("failed to parse version", e)
false
}
if (requiredVersion == null || isRequiredVersion) {
return binary
}
} catch (e: Exception) {
Expand All @@ -300,14 +308,19 @@ class MirrordBinaryManager {
try {
MirrordPathManager.getBinary(CLI_BINARY, true)?.let {
val binary = MirrordBinary(it, wslDistribution)
if (requiredVersion == null || requiredVersion == binary.version) {
val isRequiredVersion = try {
Version.valueOf(binary.version).equals(Version.valueOf(requiredVersion))
} catch (e: Exception) {
MirrordLogger.logger.debug("failed to parse version", e)
false
}
if (requiredVersion == null || isRequiredVersion) {
return binary
}
}
} catch (e: Exception) {
MirrordLogger.logger.debug("failed to find mirrord in plugin storage", e)
}

return null
}

Expand Down

0 comments on commit 88039fe

Please sign in to comment.