Skip to content

Commit bfac905

Browse files
committed
Add support for rollForward in global.json
1 parent 46ddb46 commit bfac905

10 files changed

+143
-29
lines changed

Diff for: src/dotnet-install.sh

+75-29
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ get_version_from_latestversion_file() {
638638

639639
# args:
640640
# json_file - $1
641-
parse_globaljson_file_for_version() {
641+
parse_globaljson_file() {
642642
eval $invocation
643643

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

660-
local version_info=""
661660
while read -r line; do
662661
IFS=:
663662
while read -r key value; do
664663
if [[ "$key" == "version" ]]; then
665-
version_info=$value
664+
globaljson_version=$value
665+
elif [[ "$key" == "rollForward" ]]; then
666+
globaljson_roll_forward=$value
666667
fi
667668
done <<< "$line"
668669
done <<< "$sdk_list"
669-
if [ -z "$version_info" ]; then
670-
say_err "Unable to find the SDK:version node in \`$json_file\`"
671-
return 1
672-
fi
673670

674671
unset IFS;
675-
echo "$version_info"
676672
return 0
677673
}
678674

675+
process_globaljson_file() {
676+
if [[ -n "$json_file" ]]; then
677+
globaljson_version=""
678+
globaljson_roll_forward=""
679+
parse_globaljson_file "$json_file" || return 1
680+
681+
# https://learn.microsoft.com/en-us/dotnet/core/tools/global-json#matching-rules
682+
if [[ -z "$globaljson_roll_forward" ]]; then
683+
if [[ -z "$globaljson_version" ]]; then
684+
globaljson_roll_forward="latestMajor"
685+
else
686+
globaljson_roll_forward="latestPatch"
687+
fi
688+
fi
689+
690+
if [[ -n "$globaljson_version" ]]; then
691+
IFS='.'
692+
read -ra parts <<<"$globaljson_version"
693+
unset IFS
694+
695+
local major="${parts[0]}"
696+
local minor="${parts[1]}"
697+
local featureBand="${parts[2]:0:1}"
698+
fi
699+
700+
case "$globaljson_roll_forward" in
701+
disable|major|minor|feature|patch)
702+
version="$globaljson_version";
703+
;;
704+
705+
latestMajor)
706+
version="latest"
707+
channel="STS" # TODO this doesn't do what it should https://github.com/dotnet/install-scripts/issues/418
708+
;;
709+
710+
latestMinor)
711+
version="latest"
712+
channel="${major}.x" # TODO this doesn't work
713+
;;
714+
715+
latestFeature)
716+
version="latest"
717+
channel="${major}.${minor}"
718+
;;
719+
720+
latestPatch)
721+
version="latest"
722+
channel="${major}.${minor}.${featureBand}xx"
723+
;;
724+
725+
*)
726+
say_err "Unsupported rollForward option: $globaljson_roll_forward"
727+
return 1
728+
;;
729+
esac
730+
fi
731+
}
732+
679733
# args:
680734
# azure_feed - $1
681735
# channel - $2
682736
# normalized_architecture - $3
683737
# version - $4
684-
# json_file - $5
685738
get_specific_version_from_version() {
686739
eval $invocation
687740

688741
local azure_feed="$1"
689742
local channel="$2"
690743
local normalized_architecture="$3"
691744
local version="$(to_lowercase "$4")"
692-
local json_file="$5"
693-
694-
if [ -z "$json_file" ]; then
695-
if [[ "$version" == "latest" ]]; then
696-
local version_info
697-
version_info="$(get_version_from_latestversion_file "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1
698-
say_verbose "get_specific_version_from_version: version_info=$version_info"
699-
echo "$version_info" | get_version_from_latestversion_file_content
700-
return 0
701-
else
702-
echo "$version"
703-
return 0
704-
fi
705-
else
745+
746+
if [[ "$version" == "latest" ]]; then
706747
local version_info
707-
version_info="$(parse_globaljson_file_for_version "$json_file")" || return 1
708-
echo "$version_info"
748+
version_info="$(get_version_from_latestversion_file "$azure_feed" "$channel" "$normalized_architecture" false)" || return 1
749+
say_verbose "get_specific_version_from_version: version_info=$version_info"
750+
echo "$version_info" | get_version_from_latestversion_file_content
751+
return 0
752+
else
753+
echo "$version"
709754
return 0
710755
fi
711756
}
@@ -1361,8 +1406,8 @@ generate_akams_links() {
13611406
return 1
13621407
fi
13631408
1364-
if [[ -n "$json_file" || "$normalized_version" != "latest" ]]; then
1365-
# aka.ms links are not needed when exact version is specified via command or json file
1409+
if [[ "$normalized_version" != "latest" ]]; then
1410+
# aka.ms links are not needed when exact version is specified via command
13661411
return
13671412
fi
13681413
@@ -1416,7 +1461,7 @@ generate_regular_links() {
14161461
local feed="$1"
14171462
local valid_legacy_download_link=true
14181463
1419-
specific_version=$(get_specific_version_from_version "$feed" "$channel" "$normalized_architecture" "$version" "$json_file") || specific_version='0'
1464+
specific_version=$(get_specific_version_from_version "$feed" "$channel" "$normalized_architecture" "$version") || specific_version='0'
14201465
14211466
if [[ "$specific_version" == '0' ]]; then
14221467
say_verbose "Failed to resolve the specific version number using feed '$feed'"
@@ -1503,6 +1548,7 @@ calculate_vars() {
15031548
say_verbose "Normalized product: '$normalized_product'."
15041549
install_root="$(resolve_installation_path "$install_dir")"
15051550
say_verbose "InstallRoot: '$install_root'."
1551+
say_verbose "Version: '$version'."
15061552
15071553
normalized_architecture="$(get_normalized_architecture_for_specific_sdk_version "$version" "$normalized_channel" "$normalized_architecture")"
15081554
@@ -1799,7 +1845,6 @@ do
17991845
echo " -SkipNonVersionedFiles"
18001846
echo " --no-cdn,-NoCdn Disable downloading from the Azure CDN, and use the uncached feed directly."
18011847
echo " --jsonfile <JSONFILE> Determines the SDK version from a user specified global.json file."
1802-
echo " Note: global.json must have a value for 'SDK:Version'"
18031848
echo " --keep-zip,-KeepZip If set, downloaded file is kept."
18041849
echo " --zip-path, -ZipPath If set, downloaded file is stored at the specified path."
18051850
echo " -?,--?,-h,--help,-Help Shows this help message"
@@ -1836,6 +1881,7 @@ if [ "$internal" = true ] && [ -z "$(echo $feed_credential)" ]; then
18361881
fi
18371882
18381883
check_min_reqs
1884+
process_globaljson_file
18391885
calculate_vars
18401886
# generate_regular_links call below will 'exit' if the determined version is already installed.
18411887
generate_download_links
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100",
4+
"rollForward": "disable"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100",
4+
"rollForward": "latestFeature"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100",
4+
"rollForward": "latestMajor"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100",
4+
"rollForward": "latestMinor"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100",
4+
"rollForward": "latestPatch"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"sdk": {
3+
}
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100"
4+
}
5+
}

Diff for: tests/Install-Scripts.Test/GivenThatIWantToGetTheSdkLinksFromAScript.cs

+26
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,32 @@ public void WhenJsonFileIsPassedToInstallScripts(string filename)
4444
commandResult.Should().HaveStdOutMatching(@"URL\s#0\s-\s(legacy|primary|aka\.ms):\shttps://");
4545
}
4646

47+
[Theory]
48+
[InlineData("NoFields.json", "STS")]
49+
[InlineData("VersionOnly.json", "8.0.1xx")]
50+
[InlineData("LatestPatch.json", "8.0.1xx")]
51+
[InlineData("LatestFeature.json", "8.0")]
52+
[InlineData("LatestMinor.json", "8.x")]
53+
[InlineData("LatestMajor.json", "STS")]
54+
[InlineData("Disable.json", "LTS", "8.0.100")]
55+
public void WhenGlobalJsonFileIsPassedToInstallScripts(string filename, string channel, string version = "latest")
56+
{
57+
var installationScriptTestsJsonFile = Path.Combine(Environment.CurrentDirectory, "Assets", "GlobalJson", filename);
58+
59+
var args = new List<string> { "-verbose", "-dryrun", "-jsonfile", installationScriptTestsJsonFile };
60+
61+
var commandResult = CreateInstallCommand(args)
62+
.CaptureStdOut()
63+
.CaptureStdErr()
64+
.Execute();
65+
66+
commandResult.Should().Pass();
67+
commandResult.Should().NotHaveStdOutContaining("dryrun");
68+
commandResult.Should().NotHaveStdOutContaining("jsonfile");
69+
commandResult.Should().HaveStdOutContaining($"Normalized channel: '{channel}'.");
70+
commandResult.Should().HaveStdOutContaining($"Version: '{version}'.");
71+
}
72+
4773
[Theory]
4874
[InlineData("-nopath", "")]
4975
[InlineData("-verbose", "")]

Diff for: tests/Install-Scripts.Test/Install-Scripts.Test.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<Content Include="Assets\InstallationScriptTestsWithVersionFieldInTheMiddle.json">
2828
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2929
</Content>
30+
<Content Include="Assets\GlobalJson\*.json">
31+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
32+
</Content>
3033
</ItemGroup>
3134

3235
<ItemGroup>

0 commit comments

Comments
 (0)