Skip to content

Commit e267fb5

Browse files
committed
Improve handling of empty 'channel' and 'quality' values
1 parent ba165db commit e267fb5

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/dotnet/scripts/dotnet-helpers.sh

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fetch_latest_version() {
5050
# Example: install_sdk "10.0" "preview"
5151
install_sdk() {
5252
local inputVersion="$1" # Could be 'latest', 'lts', 'X.Y', 'X.Y.Z', 'X.Y.4xx', or base channel when paired with quality
53-
local quality="$2" # Optional quality: preview, daily (empty implies GA)
53+
local quality="$2" # Optional quality: GA, preview, daily (empty implies GA)
5454
local version=""
5555
local channel=""
5656
if [[ "$inputVersion" == "latest" ]]; then
@@ -76,7 +76,10 @@ install_sdk() {
7676
version="$inputVersion"
7777
fi
7878

79-
local cmd=("$DOTNET_INSTALL_SCRIPT" "--version" "$version" "--channel" "$channel" "--install-dir" "$DOTNET_ROOT")
79+
local cmd=("$DOTNET_INSTALL_SCRIPT" "--version" "$version" "--install-dir" "$DOTNET_ROOT")
80+
if [ -n "$channel" ]; then
81+
cmd+=("--channel" "$channel")
82+
fi
8083
if [ -n "$quality" ]; then
8184
cmd+=("--quality" "$quality")
8285
fi
@@ -91,7 +94,7 @@ install_sdk() {
9194
install_runtime() {
9295
local runtime="$1"
9396
local inputVersion="$2" # Could be 'latest', 'lts', 'X.Y', 'X.Y.Z'
94-
local quality="$3" # Optional quality: preview, daily (empty implies GA)
97+
local quality="$3" # Optional quality: GA, preview, daily (empty implies GA)
9598
local version=""
9699
local channel=""
97100
if [[ "$inputVersion" == "latest" ]]; then
@@ -112,7 +115,10 @@ install_runtime() {
112115
version="$inputVersion"
113116
fi
114117

115-
local cmd=("$DOTNET_INSTALL_SCRIPT" "--runtime" "$runtime" "--version" "$version" "--channel" "$channel" "--install-dir" "$DOTNET_ROOT" "--no-path")
118+
local cmd=("$DOTNET_INSTALL_SCRIPT" "--runtime" "$runtime" "--version" "$version" "--install-dir" "$DOTNET_ROOT" "--no-path")
119+
if [ -n "$channel" ]; then
120+
cmd+=("--channel" "$channel")
121+
fi
116122
if [ -n "$quality" ]; then
117123
cmd+=("--quality" "$quality")
118124
fi
@@ -141,7 +147,10 @@ install_workloads() {
141147
# A.B-daily
142148
# A.B.Cxx-preview
143149
# A.B.Cxx-daily
144-
# Output (stdout): "<clean_version> <quality>" where quality is one of GA|preview|daily
150+
# Output (stdout): "<clean_version> <quality>"
151+
# - For channel specs (A.B or A.B.Cxx) without suffix -> quality is GA
152+
# - For channel specs with -preview/-daily suffix -> quality is preview/daily
153+
# - For exact version specs (contain a third numeric segment or prerelease labels beyond channel patterns, e.g. 8.0.100-rc.2.23502.2) -> quality is empty
145154
# Examples:
146155
# parse_version_and_quality "10.0-preview" => "10.0 preview"
147156
# parse_version_and_quality "10.0-daily" => "10.0 daily"
@@ -151,14 +160,28 @@ install_workloads() {
151160
# parse_version_and_quality "6.0.4xx-daily" => "6.0.4xx daily"
152161
parse_version_and_quality() {
153162
local input="$1"
154-
local quality="GA"
163+
local quality=""
155164
local clean_version="$input"
165+
# Match feature band with quality
156166
if [[ "$input" =~ ^([0-9]+\.[0-9]+\.[0-9]xx)-(preview|daily)$ ]]; then
157167
clean_version="${BASH_REMATCH[1]}"
158168
quality="${BASH_REMATCH[2]}"
169+
# Match simple channel with quality
159170
elif [[ "$input" =~ ^([0-9]+\.[0-9]+)-(preview|daily)$ ]]; then
160171
clean_version="${BASH_REMATCH[1]}"
161172
quality="${BASH_REMATCH[2]}"
173+
# Match plain feature band channel (defaults to GA)
174+
elif [[ "$input" =~ ^[0-9]+\.[0-9]+\.[0-9]xx$ ]]; then
175+
clean_version="$input"
176+
quality="GA"
177+
# Match simple channel (defaults to GA)
178+
elif [[ "$input" =~ ^[0-9]+\.[0-9]+$ ]]; then
179+
clean_version="$input"
180+
quality="GA"
181+
else
182+
# Exact version (leave quality empty)
183+
clean_version="$input"
184+
quality=""
162185
fi
163186
echo "$clean_version" "$quality"
164187
}

0 commit comments

Comments
 (0)