Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .github/workflows/long-running-azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ jobs:
persist-credentials: false

- name: Install Radius CLI from official release
shell: bash
run: |
# Install the latest Radius CLI, including release candidates if available.
# INSTALL_DIR places rad directly into the workspace bin directory — no copy needed.
mkdir -p "$GITHUB_WORKSPACE/bin"
wget -q "https://raw.githubusercontent.com/radius-project/radius/main/deploy/install.sh" -O - | INSTALL_DIR="$GITHUB_WORKSPACE/bin" INCLUDE_RC=true /bin/bash
wget --no-verbose "https://raw.githubusercontent.com/radius-project/radius/main/deploy/install.sh" -O - | INSTALL_DIR="$GITHUB_WORKSPACE/bin" INCLUDE_RC=true /bin/bash

- name: Verify CLI installation
run: |
Expand Down
34 changes: 22 additions & 12 deletions deploy/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -258,24 +258,33 @@ warnExistingRadiusElsewhere() {

getLatestRelease() {
local radReleaseUrl="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases"
local response=""
local latest_release=""

if [[ "${INCLUDE_RC}" == "true" ]]; then
if [[ "${RADIUS_HTTP_REQUEST_CLI}" == "curl" ]]; then
latest_release=$(curl -s "${radReleaseUrl}" | grep \"tag_name\" | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
else
latest_release=$(wget -q --header="Accept: application/json" -O - "${radReleaseUrl}" | grep \"tag_name\" | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
if [[ "${RADIUS_HTTP_REQUEST_CLI}" == "curl" ]]; then
# -S preserves curl's error output while -s hides the progress meter.
if ! response=$(curl -sS "${radReleaseUrl}"); then
exit 1
fi
else
if [[ "${RADIUS_HTTP_REQUEST_CLI}" == "curl" ]]; then
latest_release=$(curl -s "${radReleaseUrl}" | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
else
latest_release=$(wget -q --header="Accept: application/json" -O - "${radReleaseUrl}" | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
if ! response=$(wget --no-verbose \
--header="Accept: application/json" -O - "${radReleaseUrl}"); then
exit 1
fi
fi

if [[ "${INCLUDE_RC}" == "true" ]]; then
latest_release=$(printf '%s\n' "${response}" | grep \"tag_name\" |
awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p') || true
else
latest_release=$(printf '%s\n' "${response}" | grep \"tag_name\" |
grep -v rc | awk 'NR==1{print $2}' |
sed -n 's/\"\(.*\)\",/\1/p') || true
fi

if [[ -z "${latest_release}" ]]; then
echo "Error: could not determine latest release"
echo "Error: could not determine latest release" >&2
echo "Response: ${response:0:500}" >&2
exit 1
fi

Expand Down Expand Up @@ -313,9 +322,10 @@ downloadFile() {

echo "Downloading ${download_url}..."
if [[ "${RADIUS_HTTP_REQUEST_CLI}" == "curl" ]]; then
curl -SsL "${download_url}" -o "${artifact_tmp_file}"
curl --fail --show-error --silent --location "${download_url}" \
-o "${artifact_tmp_file}"
else
wget -q -O "${artifact_tmp_file}" "${download_url}"
wget --no-verbose -O "${artifact_tmp_file}" "${download_url}"
fi
fi

Expand Down
73 changes: 73 additions & 0 deletions deploy/test-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ make_test_dir() {
echo "${dir}"
}

# Create a bin directory holding the tools install.sh needs plus a stub curl,
# so HTTP failures can be simulated without network access.
make_stub_curl_bin() {
local name="$1"
local script="$2"
local bin_dir
bin_dir=$(make_test_dir "${name}")

local tool tool_path
for tool in bash mktemp rm uname tr grep awk sed; do
tool_path=$(command -v "${tool}" 2>/dev/null) || continue
ln -sf "${tool_path}" "${bin_dir}/"
done

printf '%s\n' "${script}" > "${bin_dir}/curl"
chmod +x "${bin_dir}/curl"
echo "${bin_dir}"
}

# Assert rad binary exists, is executable, and can report its version.
assert_rad_installed() {
local dir="$1"
Expand Down Expand Up @@ -357,6 +376,57 @@ test_edge_version_with_oras() {
assert_rad_installed "${dir}"
}

test_transport_error_visible() {
local dir bin_dir
dir=$(make_test_dir "transport-error")
bin_dir=$(make_stub_curl_bin "transport-error-bin" '#!/bin/bash
echo "curl: (7) Failed to connect to api.github.com port 443" >&2
exit 7')

echo " CMD: PATH=<failing-curl> ${INSTALLER} --install-dir ${dir}"
if LAST_OUTPUT=$(PATH="${bin_dir}" "${INSTALLER}" \
--install-dir "${dir}" 2>&1); then
echo " ASSERT FAILED: expected non-zero exit for transport error"
return 1
fi
echo "${LAST_OUTPUT}"
assert_contains "${LAST_OUTPUT}" "curl: (7) Failed to connect"
}

test_api_error_body_visible() {
local dir bin_dir
dir=$(make_test_dir "api-error-body")
bin_dir=$(make_stub_curl_bin "api-error-body-bin" '#!/bin/bash
printf "%s" "{\"message\":\"API rate limit exceeded for 203.0.113.5.\"}"
exit 0')

echo " CMD: PATH=<rate-limited-curl> ${INSTALLER} --install-dir ${dir}"
if LAST_OUTPUT=$(PATH="${bin_dir}" "${INSTALLER}" \
--install-dir "${dir}" 2>&1); then
echo " ASSERT FAILED: expected non-zero exit for API error response"
return 1
fi
echo "${LAST_OUTPUT}"
assert_contains "${LAST_OUTPUT}" "API rate limit exceeded"
}

test_artifact_download_error_visible() {
local dir bin_dir
dir=$(make_test_dir "artifact-download-error")
bin_dir=$(make_stub_curl_bin "artifact-download-error-bin" '#!/bin/bash
echo "curl: (22) The requested URL returned error: 404" >&2
exit 22')

echo " CMD: PATH=<failing-curl> ${INSTALLER} --version ${PINNED_VERSION} --install-dir ${dir}"
if LAST_OUTPUT=$(PATH="${bin_dir}" "${INSTALLER}" \
--version "${PINNED_VERSION}" --install-dir "${dir}" 2>&1); then
echo " ASSERT FAILED: expected non-zero exit for download error"
return 1
fi
echo "${LAST_OUTPUT}"
assert_contains "${LAST_OUTPUT}" "curl: (22)"
}

test_flag_overrides_install_dir_env() {
local env_dir flag_dir
env_dir=$(make_test_dir "env-dir-ignored")
Expand Down Expand Up @@ -499,6 +569,9 @@ run_test "PATH hint shown for non-PATH dir" test_path_hint_shown
run_test "version with v prefix" test_version_with_v_prefix
run_test "edge version without oras fails" test_edge_version_without_oras
run_test "edge version with oras succeeds" test_edge_version_with_oras
run_test "latest release transport error is visible" test_transport_error_visible
run_test "latest release API error body is visible" test_api_error_body_visible
run_test "artifact download error is visible" test_artifact_download_error_visible
run_test "--install-dir flag overrides INSTALL_DIR env" test_flag_overrides_install_dir_env
run_test "INSTALL_DIR env overrides RADIUS_INSTALL_DIR" test_install_dir_env_overrides_radius_install_dir
run_test "warning for existing rad elsewhere in PATH" test_warn_existing_rad_elsewhere
Expand Down
Loading