Skip to content

Commit

Permalink
Fix selfupdate.
Browse files Browse the repository at this point in the history
Compare local and remote versions on selfupdate.
  • Loading branch information
marc0der committed Mar 19, 2023
1 parent e784383 commit 8a8c69d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 36 deletions.
21 changes: 17 additions & 4 deletions src/main/bash/sdkman-selfupdate.sh
Expand Up @@ -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
}
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/test/groovy/sdkman/steps/initialisation_steps.groovy
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
16 changes: 0 additions & 16 deletions src/test/resources/features/idempotent_self_update.feature

This file was deleted.

20 changes: 8 additions & 12 deletions src/test/resources/features/self_update.feature
Expand Up @@ -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."

0 comments on commit 8a8c69d

Please sign in to comment.