Skip to content
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

Add support for rollForward in global.json #472

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
104 changes: 75 additions & 29 deletions src/dotnet-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ get_version_from_latestversion_file() {

# args:
# json_file - $1
parse_globaljson_file_for_version() {
parse_globaljson_file() {
eval $invocation

local json_file="$1"
Expand All @@ -657,55 +657,100 @@ parse_globaljson_file_for_version() {
sdk_list=${sdk_list//[\" ]/}
sdk_list=${sdk_list//,/$'\n'}

local version_info=""
while read -r line; do
IFS=:
while read -r key value; do
if [[ "$key" == "version" ]]; then
version_info=$value
globaljson_version=$value
elif [[ "$key" == "rollForward" ]]; then
globaljson_roll_forward=$value
fi
done <<< "$line"
done <<< "$sdk_list"
if [ -z "$version_info" ]; then
say_err "Unable to find the SDK:version node in \`$json_file\`"
return 1
fi

unset IFS;
echo "$version_info"
return 0
}

process_globaljson_file() {
if [[ -n "$json_file" ]]; then
globaljson_version=""
globaljson_roll_forward=""
parse_globaljson_file "$json_file" || return 1

# https://learn.microsoft.com/en-us/dotnet/core/tools/global-json#matching-rules
if [[ -z "$globaljson_roll_forward" ]]; then
if [[ -z "$globaljson_version" ]]; then
globaljson_roll_forward="latestMajor"
else
globaljson_roll_forward="latestPatch"
fi
fi

if [[ -n "$globaljson_version" ]]; then
IFS='.'
read -ra parts <<<"$globaljson_version"
unset IFS

local major="${parts[0]}"
local minor="${parts[1]}"
local featureBand="${parts[2]:0:1}"
fi

case "$globaljson_roll_forward" in
disable|major|minor|feature|patch)
version="$globaljson_version";
;;

latestMajor)
version="latest"
channel="STS" # TODO this doesn't do what it should https://github.com/dotnet/install-scripts/issues/418
;;

latestMinor)
version="latest"
channel="${major}.x" # TODO this doesn't work
;;

latestFeature)
version="latest"
channel="${major}.${minor}"
;;

latestPatch)
version="latest"
channel="${major}.${minor}.${featureBand}xx"
;;

*)
say_err "Unsupported rollForward option: $globaljson_roll_forward"
return 1
;;
esac
fi
}

# args:
# azure_feed - $1
# channel - $2
# normalized_architecture - $3
# version - $4
# json_file - $5
get_specific_version_from_version() {
eval $invocation

local azure_feed="$1"
local channel="$2"
local normalized_architecture="$3"
local version="$(to_lowercase "$4")"
local json_file="$5"

if [ -z "$json_file" ]; then
if [[ "$version" == "latest" ]]; then
local version_info
version_info="$(get_version_from_latestversion_file "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1
say_verbose "get_specific_version_from_version: version_info=$version_info"
echo "$version_info" | get_version_from_latestversion_file_content
return 0
else
echo "$version"
return 0
fi
else

if [[ "$version" == "latest" ]]; then
local version_info
version_info="$(parse_globaljson_file_for_version "$json_file")" || return 1
echo "$version_info"
version_info="$(get_version_from_latestversion_file "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1
say_verbose "get_specific_version_from_version: version_info=$version_info"
echo "$version_info" | get_version_from_latestversion_file_content
return 0
else
echo "$version"
return 0
fi
}
Expand Down Expand Up @@ -1361,8 +1406,8 @@ generate_akams_links() {
return 1
fi

if [[ -n "$json_file" || "$normalized_version" != "latest" ]]; then
# aka.ms links are not needed when exact version is specified via command or json file
if [[ "$normalized_version" != "latest" ]]; then
# aka.ms links are not needed when exact version is specified via command
return
fi

Expand Down Expand Up @@ -1416,7 +1461,7 @@ generate_regular_links() {
local feed="$1"
local valid_legacy_download_link=true

specific_version=$(get_specific_version_from_version "$feed" "$channel" "$normalized_architecture" "$version" "$json_file") || specific_version='0'
specific_version=$(get_specific_version_from_version "$feed" "$channel" "$normalized_architecture" "$version") || specific_version='0'

if [[ "$specific_version" == '0' ]]; then
say_verbose "Failed to resolve the specific version number using feed '$feed'"
Expand Down Expand Up @@ -1503,6 +1548,7 @@ calculate_vars() {
say_verbose "Normalized product: '$normalized_product'."
install_root="$(resolve_installation_path "$install_dir")"
say_verbose "InstallRoot: '$install_root'."
say_verbose "Version: '$version'."

normalized_architecture="$(get_normalized_architecture_for_specific_sdk_version "$version" "$normalized_channel" "$normalized_architecture")"

Expand Down Expand Up @@ -1799,7 +1845,6 @@ do
echo " -SkipNonVersionedFiles"
echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly."
echo " --jsonfile <JSONFILE> Determines the SDK version from a user specified global.json file."
echo " Note: global.json must have a value for 'SDK:Version'"
echo " --keep-zip,-KeepZip If set, downloaded file is kept."
echo " --zip-path, -ZipPath If set, downloaded file is stored at the specified path."
echo " -?,--?,-h,--help,-Help Shows this help message"
Expand Down Expand Up @@ -1836,6 +1881,7 @@ if [ "$internal" = true ] && [ -z "$(echo $feed_credential)" ]; then
fi

check_min_reqs
process_globaljson_file
calculate_vars
# generate_regular_links call below will 'exit' if the determined version is already installed.
generate_download_links
Expand Down
6 changes: 6 additions & 0 deletions tests/Install-Scripts.Test/Assets/GlobalJson/Disable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "disable"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestFeature"
}
}
6 changes: 6 additions & 0 deletions tests/Install-Scripts.Test/Assets/GlobalJson/LatestMajor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestMajor"
}
}
6 changes: 6 additions & 0 deletions tests/Install-Scripts.Test/Assets/GlobalJson/LatestMinor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestMinor"
}
}
6 changes: 6 additions & 0 deletions tests/Install-Scripts.Test/Assets/GlobalJson/LatestPatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestPatch"
}
}
4 changes: 4 additions & 0 deletions tests/Install-Scripts.Test/Assets/GlobalJson/NoFields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"sdk": {
}
}
5 changes: 5 additions & 0 deletions tests/Install-Scripts.Test/Assets/GlobalJson/VersionOnly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "8.0.100"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ public void WhenJsonFileIsPassedToInstallScripts(string filename)
commandResult.Should().HaveStdOutMatching(@"URL\s#0\s-\s(legacy|primary|aka\.ms):\shttps://");
}

[Theory]
[InlineData("NoFields.json", "STS")]
[InlineData("VersionOnly.json", "8.0.1xx")]
[InlineData("LatestPatch.json", "8.0.1xx")]
[InlineData("LatestFeature.json", "8.0")]
[InlineData("LatestMinor.json", "8.x")]
[InlineData("LatestMajor.json", "STS")]
[InlineData("Disable.json", "LTS", "8.0.100")]
public void WhenGlobalJsonFileIsPassedToInstallScripts(string filename, string channel, string version = "latest")
{
var installationScriptTestsJsonFile = Path.Combine(Environment.CurrentDirectory, "Assets", "GlobalJson", filename);

var args = new List<string> { "-verbose", "-dryrun", "-jsonfile", installationScriptTestsJsonFile };

var commandResult = CreateInstallCommand(args)
.CaptureStdOut()
.CaptureStdErr()
.Execute();

commandResult.Should().Pass();
commandResult.Should().NotHaveStdOutContaining("dryrun");
commandResult.Should().NotHaveStdOutContaining("jsonfile");
commandResult.Should().HaveStdOutContaining($"Normalized channel: '{channel}'.");
commandResult.Should().HaveStdOutContaining($"Version: '{version}'.");
}

[Theory]
[InlineData("-nopath", "")]
[InlineData("-verbose", "")]
Expand Down
3 changes: 3 additions & 0 deletions tests/Install-Scripts.Test/Install-Scripts.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<Content Include="Assets\InstallationScriptTestsWithVersionFieldInTheMiddle.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Assets\GlobalJson\*.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down
Loading