Fix selfupdate.

Compare local and remote versions on selfupdate.
This commit is contained in:
Marco Vermeulen
2023-03-18 17:38:02 +00:00
committed by Marco Vermeulen
parent e78438370d
commit 8a8c69de2d
5 changed files with 29 additions and 36 deletions

View File

@@ -18,17 +18,30 @@
function __sdk_selfupdate() {
local force_selfupdate
local sdkman_version_api
force_selfupdate="$1"
if [[ "$SDKMAN_AVAILABLE" == "false" ]]; then
echo "This command is not available while offline."
elif [[ "$SDKMAN_REMOTE_VERSION" == "$SDKMAN_VERSION" && "$force_selfupdate" != "force" ]]; then
return 1
fi
if [[ "$sdkman_beta_channel" == "true" ]]; then
sdkman_version_api="${SDKMAN_CANDIDATES_API}/broker/version/sdkman/script/beta"
else
sdkman_version_api="${SDKMAN_CANDIDATES_API}/broker/version/sdkman/script/stable"
fi
sdkman_remote_version=$(__sdkman_secure_curl "$sdkman_version_api")
sdkman_local_version=$(cat "$SDKMAN_DIR/var/version")
__sdkman_echo_debug "Local version: $sdkman_local_version; remote version: $sdkman_remote_version"
force_selfupdate="$1"
export sdkman_debug_mode
if [[ "$sdkman_local_version" == "$sdkman_remote_version" && "$force_selfupdate" != "force" ]]; then
echo "No update available at this time."
elif [[ "$sdkman_beta_channel" == "true" ]]; then
export sdkman_debug_mode
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/selfupdate/beta/${SDKMAN_PLATFORM}" | bash
else
export sdkman_debug_mode
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/selfupdate/stable/${SDKMAN_PLATFORM}" | bash
fi
}

View File

@@ -6,7 +6,7 @@ import java.time.Instant
import static java.time.temporal.ChronoUnit.DAYS
class SelfupdateSpec extends SdkmanEnvSpecification {
class SelfupdateFeatureSpec extends SdkmanEnvSpecification {
static final String CANDIDATES_API = "http://localhost:8080/2"
static final String HEALTHCHECK_ENDPOINT = "$CANDIDATES_API/healthcheck"
static final String VERSION_ENDPOINT = "$CANDIDATES_API/broker/download/sdkman/version/stable"

View File

@@ -34,7 +34,7 @@ And(~'^the archive for candidate "([^"]*)" version "([^"]*)" is removed$') { Str
And(~'^the internet is reachable$') { ->
primeEndpointWithString("/healthcheck", "12345")
primeEndpointWithString("/app/stable", sdkmanVersion)
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
primeSelfupdate()
offlineMode = false
@@ -50,7 +50,7 @@ And(~'^the internet is not reachable$') { ->
And(~'^offline mode is disabled with reachable internet$') { ->
primeEndpointWithString("/healthcheck", "12345")
primeEndpointWithString("/app/stable", sdkmanVersion)
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
offlineMode = false
serviceUrlEnv = SERVICE_UP_URL
@@ -59,7 +59,7 @@ And(~'^offline mode is disabled with reachable internet$') { ->
And(~'^offline mode is enabled with reachable internet$') { ->
primeEndpointWithString("/healthcheck", "12345")
primeEndpointWithString("/app/stable", sdkmanVersion)
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
offlineMode = true
serviceUrlEnv = SERVICE_UP_URL

View File

@@ -1,16 +0,0 @@
Feature: Idempotent Self Update
Background:
Given the internet is reachable
And an initialised environment
And the system is bootstrapped
And an available selfupdate
Scenario: Attempt Self Update on an up to date system
When I enter "sdk selfupdate"
#TODO Fix this without relying on version file
#Then I see "No update available at this time."
Scenario: Force Self Update on an up to date system
When I enter "sdk selfupdate force"
Then I see "Successfully upgraded SDKMAN."

View File

@@ -3,19 +3,15 @@ Feature: Self Update
Background:
Given the internet is reachable
Scenario: Force a Selfupdate
Given an initialised environment
And an initialised environment
And the system is bootstrapped
When I enter "sdk selfupdate force"
Then I do not see "A new version of SDKMAN is available..."
And I do not see "Would you like to upgrade now? (Y/n)"
And I do not see "Not upgrading today..."
And I see "Updating SDKMAN..."
And I see "Successfully upgraded SDKMAN."
And an available selfupdate
Scenario: Selfupdate when not out of date
Given an initialised environment
And the system is bootstrapped
Scenario: Attempt Self Update on an up to date system
When I enter "sdk selfupdate"
Then I see "No update available at this time."
Scenario: Force Self Update on an up to date system
When I enter "sdk selfupdate force"
Then I see "Successfully upgraded SDKMAN."