Skip to content

Commit 8a8c69d

Browse files
committed
Fix selfupdate.
Compare local and remote versions on selfupdate.
1 parent e784383 commit 8a8c69d

File tree

5 files changed

+29
-36
lines changed

5 files changed

+29
-36
lines changed

src/main/bash/sdkman-selfupdate.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,30 @@
1818

1919
function __sdk_selfupdate() {
2020
local force_selfupdate
21+
local sdkman_version_api
2122

22-
force_selfupdate="$1"
2323
if [[ "$SDKMAN_AVAILABLE" == "false" ]]; then
2424
echo "This command is not available while offline."
25-
elif [[ "$SDKMAN_REMOTE_VERSION" == "$SDKMAN_VERSION" && "$force_selfupdate" != "force" ]]; then
25+
return 1
26+
fi
27+
28+
if [[ "$sdkman_beta_channel" == "true" ]]; then
29+
sdkman_version_api="${SDKMAN_CANDIDATES_API}/broker/version/sdkman/script/beta"
30+
else
31+
sdkman_version_api="${SDKMAN_CANDIDATES_API}/broker/version/sdkman/script/stable"
32+
fi
33+
34+
sdkman_remote_version=$(__sdkman_secure_curl "$sdkman_version_api")
35+
sdkman_local_version=$(cat "$SDKMAN_DIR/var/version")
36+
__sdkman_echo_debug "Local version: $sdkman_local_version; remote version: $sdkman_remote_version"
37+
38+
force_selfupdate="$1"
39+
export sdkman_debug_mode
40+
if [[ "$sdkman_local_version" == "$sdkman_remote_version" && "$force_selfupdate" != "force" ]]; then
2641
echo "No update available at this time."
2742
elif [[ "$sdkman_beta_channel" == "true" ]]; then
28-
export sdkman_debug_mode
2943
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/selfupdate/beta/${SDKMAN_PLATFORM}" | bash
3044
else
31-
export sdkman_debug_mode
3245
__sdkman_secure_curl "${SDKMAN_CANDIDATES_API}/selfupdate/stable/${SDKMAN_PLATFORM}" | bash
3346
fi
3447
}

src/test/groovy/sdkman/specs/SelfupdateSpec.groovy renamed to src/test/groovy/sdkman/specs/SelfupdateFeatureSpec.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.time.Instant
66

77
import static java.time.temporal.ChronoUnit.DAYS
88

9-
class SelfupdateSpec extends SdkmanEnvSpecification {
9+
class SelfupdateFeatureSpec extends SdkmanEnvSpecification {
1010
static final String CANDIDATES_API = "http://localhost:8080/2"
1111
static final String HEALTHCHECK_ENDPOINT = "$CANDIDATES_API/healthcheck"
1212
static final String VERSION_ENDPOINT = "$CANDIDATES_API/broker/download/sdkman/version/stable"

src/test/groovy/sdkman/steps/initialisation_steps.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ And(~'^the archive for candidate "([^"]*)" version "([^"]*)" is removed$') { Str
3434

3535
And(~'^the internet is reachable$') { ->
3636
primeEndpointWithString("/healthcheck", "12345")
37-
primeEndpointWithString("/app/stable", sdkmanVersion)
37+
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
3838
primeSelfupdate()
3939

4040
offlineMode = false
@@ -50,7 +50,7 @@ And(~'^the internet is not reachable$') { ->
5050

5151
And(~'^offline mode is disabled with reachable internet$') { ->
5252
primeEndpointWithString("/healthcheck", "12345")
53-
primeEndpointWithString("/app/stable", sdkmanVersion)
53+
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
5454

5555
offlineMode = false
5656
serviceUrlEnv = SERVICE_UP_URL
@@ -59,7 +59,7 @@ And(~'^offline mode is disabled with reachable internet$') { ->
5959

6060
And(~'^offline mode is enabled with reachable internet$') { ->
6161
primeEndpointWithString("/healthcheck", "12345")
62-
primeEndpointWithString("/app/stable", sdkmanVersion)
62+
primeEndpointWithString("/broker/version/sdkman/script/stable", sdkmanVersion)
6363

6464
offlineMode = true
6565
serviceUrlEnv = SERVICE_UP_URL

src/test/resources/features/idempotent_self_update.feature

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/test/resources/features/self_update.feature

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ Feature: Self Update
33

44
Background:
55
Given the internet is reachable
6-
7-
Scenario: Force a Selfupdate
8-
Given an initialised environment
6+
And an initialised environment
97
And the system is bootstrapped
10-
When I enter "sdk selfupdate force"
11-
Then I do not see "A new version of SDKMAN is available..."
12-
And I do not see "Would you like to upgrade now? (Y/n)"
13-
And I do not see "Not upgrading today..."
14-
And I see "Updating SDKMAN..."
15-
And I see "Successfully upgraded SDKMAN."
8+
And an available selfupdate
169

17-
Scenario: Selfupdate when not out of date
18-
Given an initialised environment
19-
And the system is bootstrapped
10+
Scenario: Attempt Self Update on an up to date system
2011
When I enter "sdk selfupdate"
2112
Then I see "No update available at this time."
13+
14+
Scenario: Force Self Update on an up to date system
15+
When I enter "sdk selfupdate force"
16+
Then I see "Successfully upgraded SDKMAN."
17+

0 commit comments

Comments
 (0)