Skip to content

Add CI mode support to beta installation template #64

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

Merged
merged 3 commits into from
Apr 3, 2025
Merged
Changes from all 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
8 changes: 5 additions & 3 deletions app/controllers/InstallController.scala
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class InstallController @Inject() (

private val betaBaseUrlO = configUrl("service.betaBaseUrl")

def install(beta: Boolean, rcUpdate: Option[Boolean]) = Action.async { _ =>
def install(beta: Boolean, rcUpdate: Option[Boolean], ci: Option[Boolean]) = Action.async { _ =>
appRepo.findApplication().map { maybeApp =>
val response = for {
stableBaseUrl <- stableBaseUrlO
@@ -37,7 +37,8 @@ class InstallController @Inject() (
cliNativeVersion = betaNativeVersion,
baseUrl = betaBaseUrl,
rcUpdate = rcUpdate.getOrElse(true),
beta = true
beta = true,
ci = ci.getOrElse(false)
)
)
} else {
@@ -47,7 +48,8 @@ class InstallController @Inject() (
cliNativeVersion = stableNativeVersion,
baseUrl = stableBaseUrl,
rcUpdate = rcUpdate.getOrElse(true),
beta = false
beta = false,
ci = ci.getOrElse(false)
)
)
}
19 changes: 16 additions & 3 deletions app/views/install_beta.scala.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(cliVersion: String, cliNativeVersion: String, baseUrl: String, rcUpdate: Boolean, beta: Boolean)#!/bin/bash
@(cliVersion: String, cliNativeVersion: String, baseUrl: String, rcUpdate: Boolean, beta: Boolean, ci: Boolean)#!/bin/bash
@includes.license()

@includes.statusline("install", cliVersion, cliNativeVersion, baseUrl, beta)
@@ -68,22 +68,35 @@ echo "$SDKMAN_PLATFORM" > "$sdkman_platform_file"

echo "Prime the config file..."
touch "$sdkman_config_file"

@if(ci) {
# CI mode - optimized for automated environments
echo "sdkman_auto_answer=true" >> "$sdkman_config_file"
echo "sdkman_colour_enable=false" >> "$sdkman_config_file"
echo "sdkman_selfupdate_feature=false" >> "$sdkman_config_file"
} else {
# Interactive mode - optimized for human use
echo "sdkman_auto_answer=false" >> "$sdkman_config_file"
echo "sdkman_colour_enable=true" >> "$sdkman_config_file"
echo "sdkman_selfupdate_feature=true" >> "$sdkman_config_file"
}

# Set shell-specific config
if [ -z "$ZSH_VERSION" -a -z "$BASH_VERSION" ]; then
echo "sdkman_auto_complete=false" >> "$sdkman_config_file"
else
echo "sdkman_auto_complete=true" >> "$sdkman_config_file"
fi

# Common settings that don't change based on CI mode
echo "sdkman_auto_env=false" >> "$sdkman_config_file"
echo "sdkman_beta_channel=@beta" >> "$sdkman_config_file"
echo "sdkman_checksum_enable=true" >> "$sdkman_config_file"
echo "sdkman_colour_enable=true" >> "$sdkman_config_file"
echo "sdkman_curl_connect_timeout=7" >> "$sdkman_config_file"
echo "sdkman_curl_max_time=10" >> "$sdkman_config_file"
echo "sdkman_debug_mode=false" >> "$sdkman_config_file"
echo "sdkman_insecure_ssl=false" >> "$sdkman_config_file"
echo "sdkman_native_enable=true" >> "$sdkman_config_file"
echo "sdkman_selfupdate_feature=true" >> "$sdkman_config_file"

# script cli distribution
echo "Installing script cli archive..."
2 changes: 1 addition & 1 deletion app/views/install_stable.scala.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(cliVersion: String, cliNativeVersion: String, baseUrl: String, rcUpdate: Boolean, beta: Boolean)#!/bin/bash
@(cliVersion: String, cliNativeVersion: String, baseUrl: String, rcUpdate: Boolean, beta: Boolean, ci: Boolean)#!/bin/bash
@includes.license()

@includes.statusline("install", cliVersion, cliNativeVersion, baseUrl, beta)
4 changes: 2 additions & 2 deletions conf/routes
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@
# ~~~~

GET /alive controllers.HealthController.alive
GET /install/beta controllers.InstallController.install(beta: Boolean = true, rcupdate: Option[Boolean])
GET /install/stable controllers.InstallController.install(beta: Boolean = false, rcupdate: Option[Boolean])
GET /install/beta controllers.InstallController.install(beta: Boolean = true, rcupdate: Option[Boolean], ci: Option[Boolean])
GET /install/stable controllers.InstallController.install(beta: Boolean = false, rcupdate: Option[Boolean], ci: Option[Boolean])
GET /selfupdate/beta/:platform controllers.SelfUpdateController.selfUpdate(beta: Boolean = true, platform)
GET /selfupdate/beta controllers.SelfUpdateController.selfUpdate(beta: Boolean = true, platform = "unknown")
GET /selfupdate/stable/:platform controllers.SelfUpdateController.selfUpdate(beta: Boolean ?= false, platform)
14 changes: 13 additions & 1 deletion features/installation.feature
Original file line number Diff line number Diff line change
@@ -55,4 +55,16 @@ Feature: Installation
And a "text/plain; charset=UTF-8" content type is received
And the response script contains "# install:- channel: beta"
And the response script contains "Attempt update of interactive bash profile "
And the response script contains "Attempt update of zsh profile...""
And the response script contains "Attempt update of zsh profile..."

Scenario: Install SDKMAN beta in CI mode
When a request is made to the /install/beta?ci=true endpoint
Then a 200 status code is received
And a "text/plain; charset=UTF-8" content type is received
And the response script contains "# install:- channel: beta"
And the response script contains "sdkman_auto_answer=true"
And the response script contains "sdkman_colour_enable=false"
And the response script contains "sdkman_selfupdate_feature=false"
And the response script does not contain "sdkman_auto_answer=false"
And the response script does not contain "sdkman_colour_enable=true"
And the response script does not contain "sdkman_selfupdate_feature=true"
9 changes: 7 additions & 2 deletions test/steps/Steps.scala
Original file line number Diff line number Diff line change
@@ -26,11 +26,16 @@ class Steps extends ScalaDsl with EN with Matchers {
And("""^the stable native CLI Version is "(.*)"""") { native: String =>
stableNativeCliVersion = native
}

And("""^the beta native CLI Version is "(.*)"""") { native: String =>
betaNativeCliVersion = native
// Insert all CLI versions after both stable and beta native CLI versions are set
Mongo.insertCliVersions(stableCliVersion, betaCliVersion, stableNativeCliVersion, betaNativeCliVersion)
Mongo.insertCliVersions(
stableCliVersion,
betaCliVersion,
stableNativeCliVersion,
betaNativeCliVersion
)
}

And("""^a request is made to the (.*) endpoint$""") { endpoint: String =>
10 changes: 9 additions & 1 deletion test/steps/support/Mongo.scala
Original file line number Diff line number Diff line change
@@ -38,7 +38,15 @@ object Mongo {
betaNativeCliVersion: String
): Seq[Completed] =
appCollection
.insertOne(Application("OK", stableCliVersion, betaCliVersion, stableNativeCliVersion, betaNativeCliVersion))
.insertOne(
Application(
"OK",
stableCliVersion,
betaCliVersion,
stableNativeCliVersion,
betaNativeCliVersion
)
)
.results()

def dropAppCollection(): Seq[Completed] = appCollection.drop().results()
2 changes: 1 addition & 1 deletion test/steps/support/World.scala
Original file line number Diff line number Diff line change
@@ -15,6 +15,6 @@ object World {
var betaCliVersion = ""

var stableNativeCliVersion = ""

var betaNativeCliVersion = ""
}