From 96c1eea40fc97b471ba0b33fcc79273c7ce586c7 Mon Sep 17 00:00:00 2001 From: Steven Date: Mon, 11 Sep 2023 20:16:24 +0200 Subject: Use dotnet-install.sh in .NET feature (#628) * Use dotnet-install.sh in .NET feature * Use latest.version files * Cleanup runtime args * Use latest.version files in tests as well * Improve tests, remove code duplication * Add stderr helper * Validate version inputs * Use suggested description Co-authored-by: Samruddhi Khandale * Shorter version description Co-authored-by: Samruddhi Khandale * Shorter version description Co-authored-by: Samruddhi Khandale * Clean up apt lists * Verify 7.0 is latest * Fix PATH, add test for .NET global tools * Include a copy of dotnet-install.sh in the Feature * Configure useful env variables * Use stringly typed booleans * Keep imperative writing style in option hints * Update maintainers Co-authored-by: Samruddhi Khandale * Move dotnet-install.sh into a vendor directory * Refactor variables * Amend * Amend 2 * Use default options from devcontainer-feature.json * Add back variables * Fix shellchek warning in fetch_latest_sdk_version * Inline install_version function * Fix ShellCheck warnings * Improve CSV parsing * Default to latest when configuring an empty version * Add support for runtime-only configurations * Move 'none' check higher up * Deduplicate helper functions, sort into files * Address the user more directly in NOTES * Remove unnecessary defaults * Replace feature -> Feature Co-authored-by: Samruddhi Khandale * Add update-dotnet-install-script workflow * Apply suggestions from code review Co-authored-by: Samruddhi Khandale * Don't skip ci for automated script update --------- Co-authored-by: Samruddhi Khandale --- test/dotnet/dotnet_env.sh | 4 ++ test/dotnet/dotnet_helpers.sh | 71 ++++++++++++++++++ test/dotnet/install_additional_dotnet.sh | 17 ----- test/dotnet/install_aspnetcore_runtime_only.sh | 27 +++++++ test/dotnet/install_dotnet_3.sh | 17 ----- test/dotnet/install_dotnet_6_bullseye.sh | 17 ----- test/dotnet/install_dotnet_6_focal.sh | 17 ----- test/dotnet/install_dotnet_6_jammy.sh | 17 ----- test/dotnet/install_dotnet_7_bullseye.sh | 17 ----- test/dotnet/install_dotnet_7_jammy.sh | 17 ----- test/dotnet/install_dotnet_exact_version.sh | 24 +++++++ test/dotnet/install_dotnet_global_tool.sh | 25 +++++++ test/dotnet/install_dotnet_latest.sh | 17 ----- .../install_dotnet_latest_when_version_is_empty.sh | 30 ++++++++ test/dotnet/install_dotnet_lts.sh | 27 ++++--- test/dotnet/install_dotnet_multiple_versions.sh | 30 ++++++++ test/dotnet/install_dotnet_runtime_only.sh | 27 +++++++ test/dotnet/install_dotnet_specific_release.sh | 26 +++++++ ...all_dotnet_specific_release_and_feature_band.sh | 24 +++++++ test/dotnet/install_wo_apt.sh | 17 ----- test/dotnet/projects/.gitignore | 2 + test/dotnet/projects/multitargeting/Class1.cs | 4 ++ .../multitargeting/example_classlib.csproj | 9 +++ test/dotnet/projects/net5.0/Program.cs | 32 +++++++++ test/dotnet/projects/net5.0/example_project.csproj | 13 ++++ test/dotnet/projects/net6.0/Program.cs | 30 ++++++++ test/dotnet/projects/net6.0/example_project.csproj | 14 ++++ test/dotnet/projects/net7.0/Program.cs | 30 ++++++++ test/dotnet/projects/net7.0/example_project.csproj | 14 ++++ test/dotnet/projects/net8.0/Program.cs | 32 +++++++++ test/dotnet/projects/net8.0/example_project.csproj | 14 ++++ test/dotnet/projects/netcoreapp3.1/Program.cs | 39 ++++++++++ .../projects/netcoreapp3.1/example_project.csproj | 14 ++++ test/dotnet/scenarios.json | 83 +++++++++++----------- test/dotnet/test.sh | 31 +++++--- 35 files changed, 615 insertions(+), 214 deletions(-) create mode 100644 test/dotnet/dotnet_env.sh create mode 100644 test/dotnet/dotnet_helpers.sh delete mode 100644 test/dotnet/install_additional_dotnet.sh create mode 100644 test/dotnet/install_aspnetcore_runtime_only.sh delete mode 100644 test/dotnet/install_dotnet_3.sh delete mode 100644 test/dotnet/install_dotnet_6_bullseye.sh delete mode 100644 test/dotnet/install_dotnet_6_focal.sh delete mode 100644 test/dotnet/install_dotnet_6_jammy.sh delete mode 100644 test/dotnet/install_dotnet_7_bullseye.sh delete mode 100644 test/dotnet/install_dotnet_7_jammy.sh create mode 100644 test/dotnet/install_dotnet_exact_version.sh create mode 100644 test/dotnet/install_dotnet_global_tool.sh delete mode 100644 test/dotnet/install_dotnet_latest.sh create mode 100644 test/dotnet/install_dotnet_latest_when_version_is_empty.sh create mode 100644 test/dotnet/install_dotnet_multiple_versions.sh create mode 100644 test/dotnet/install_dotnet_runtime_only.sh create mode 100644 test/dotnet/install_dotnet_specific_release.sh create mode 100644 test/dotnet/install_dotnet_specific_release_and_feature_band.sh delete mode 100644 test/dotnet/install_wo_apt.sh create mode 100644 test/dotnet/projects/.gitignore create mode 100644 test/dotnet/projects/multitargeting/Class1.cs create mode 100644 test/dotnet/projects/multitargeting/example_classlib.csproj create mode 100644 test/dotnet/projects/net5.0/Program.cs create mode 100644 test/dotnet/projects/net5.0/example_project.csproj create mode 100644 test/dotnet/projects/net6.0/Program.cs create mode 100644 test/dotnet/projects/net6.0/example_project.csproj create mode 100644 test/dotnet/projects/net7.0/Program.cs create mode 100644 test/dotnet/projects/net7.0/example_project.csproj create mode 100644 test/dotnet/projects/net8.0/Program.cs create mode 100644 test/dotnet/projects/net8.0/example_project.csproj create mode 100644 test/dotnet/projects/netcoreapp3.1/Program.cs create mode 100644 test/dotnet/projects/netcoreapp3.1/example_project.csproj mode change 100755 => 100644 test/dotnet/test.sh (limited to 'test/dotnet') diff --git a/test/dotnet/dotnet_env.sh b/test/dotnet/dotnet_env.sh new file mode 100644 index 0000000..37b14ea --- /dev/null +++ b/test/dotnet/dotnet_env.sh @@ -0,0 +1,4 @@ +#!/bin/bash +export DOTNET_NOLOGO=true +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true +export DOTNET_GENERATE_ASPNET_CERTIFICATE=false \ No newline at end of file diff --git a/test/dotnet/dotnet_helpers.sh b/test/dotnet/dotnet_helpers.sh new file mode 100644 index 0000000..6c833b4 --- /dev/null +++ b/test/dotnet/dotnet_helpers.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Prints the latest dotnet version in the specified channel +# Usage: fetch_latest_version_in_channel [] +# Example: fetch_latest_version_in_channel "LTS" +# Example: fetch_latest_version_in_channel "6.0" "dotnet" +# Example: fetch_latest_version_in_channel "6.0" "aspnetcore" +fetch_latest_version_in_channel() { + local channel="$1" + local runtime="$2" + if [ "$runtime" = "dotnet" ]; then + wget -qO- "https://dotnetcli.azureedge.net/dotnet/Runtime/$channel/latest.version" + elif [ "$runtime" = "aspnetcore" ]; then + wget -qO- "https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/$channel/latest.version" + else + wget -qO- "https://dotnetcli.azureedge.net/dotnet/Sdk/$channel/latest.version" + fi + +} + +# Prints the latest dotnet version +# Usage: fetch_latest_version [] +# Example: fetch_latest_version +# Example: fetch_latest_version "dotnet" +# Example: fetch_latest_version "aspnetcore" +fetch_latest_version() { + local runtime="$1" + local sts_version + local lts_version + sts_version=$(fetch_latest_version_in_channel "STS" "$runtime") + lts_version=$(fetch_latest_version_in_channel "LTS" "$runtime") + if [[ "$sts_version" > "$lts_version" ]]; then + echo "$sts_version" + else + echo "$lts_version" + fi +} + +# Asserts that the specified .NET SDK version is installed +# Returns a non-zero exit code if the check fails +# Usage: is_dotnet_sdk_version_installed +# Example: is_dotnet_sdk_version_installed "6.0" +# Example: is_dotnet_sdk_version_installed "6.0.412" +is_dotnet_sdk_version_installed() { + local expected="$1" + dotnet --list-sdks | grep --fixed-strings --silent "$expected" + return $? +} + + +# Asserts that the specified .NET Runtime version is installed +# Returns a non-zero exit code if the check fails +# Usage: is_dotnet_runtime_version_installed +# Example: is_dotnet_runtime_version_installed "6.0" +# Example: is_dotnet_runtime_version_installed "6.0.412" +is_dotnet_runtime_version_installed() { + local expected="$1" + dotnet --list-runtimes | grep --fixed-strings --silent "Microsoft.NETCore.App $expected" + return $? +} + +# Asserts that the specified ASP.NET Core Runtime version is installed +# Returns a non-zero exit code if the check fails +# Usage: is_aspnetcore_runtime_version_installed +# Example: is_aspnetcore_runtime_version_installed "6.0" +# Example: is_aspnetcore_runtime_version_installed "6.0.412" +is_aspnetcore_runtime_version_installed() { + local expected="$1" + dotnet --list-runtimes | grep --fixed-strings --silent "Microsoft.AspNetCore.App $expected" + return $? +} \ No newline at end of file diff --git a/test/dotnet/install_additional_dotnet.sh b/test/dotnet/install_additional_dotnet.sh deleted file mode 100644 index e69c7dc..0000000 --- a/test/dotnet/install_additional_dotnet.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e - -# Optional: Import test library -source dev-container-features-test-lib - -check "dotnet version 6.0.301 installed as default" bash -c "dotnet --version | grep 6.0.301" -check "dotnet version 5.0 installed" bash -c "ls -l /usr/local/dotnet | grep 5.0" -check "dotnet version 3.1.420 installed" bash -c "ls -l /usr/local/dotnet | grep 3.1.420" - -# Verify current symlink exists and works -check "current link dotnet" /usr/local/dotnet/current/dotnet --info -check "current link sdk" ls -l /usr/local/dotnet/current/sdk - -# Report result -reportResults diff --git a/test/dotnet/install_aspnetcore_runtime_only.sh b/test/dotnet/install_aspnetcore_runtime_only.sh new file mode 100644 index 0000000..35bd540 --- /dev/null +++ b/test/dotnet/install_aspnetcore_runtime_only.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check