Skip to content
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

mirrord binary download improvements #180

Merged
merged 13 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
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
Razz4780 marked this conversation as resolved.
Show resolved Hide resolved

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

val autoUpdate = MirrordSettingsState.instance.mirrordState.autoUpdate
val userSelectedMirrordVersion = MirrordSettingsState.instance.mirrordState.mirrordVersion
manager.latestSupportedVersion = manager.fetchLatestSupportedVersion(product, indicator)
Razz4780 marked this conversation as resolved.
Show resolved Hide resolved

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)
.notification("mirrord version format is invalid! ${e.message}", NotificationType.WARNING)
.fire()
return
}
userSelectedMirrordVersion
}
// auto update -> false -> mirrordVersion is empty -> needs check in the path
// if not in path -> fetch latest version
Expand All @@ -111,7 +115,7 @@ class MirrordBinaryManager {
return
}

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

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 @@ -278,7 +274,18 @@ class MirrordBinaryManager {
}

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

val isRequiredVersion = try {
Razz4780 marked this conversation as resolved.
Show resolved Hide resolved
// 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) {
false
}
if (requiredVersion == null || isRequiredVersion) {
return binary
}
} catch (e: Exception) {
Expand Down