From 3e891b0cb619bf60e2c25674b222b8940e2c1c25 Mon Sep 17 00:00:00 2001 From: John Wesley Walker III <81404201+jww3@users.noreply.github.com> Date: Mon, 21 Oct 2024 20:32:55 +0200 Subject: [PATCH] Revise `isGhes` logic (#556) * Revise `isGhes` logic * `isGhes` should not be exported * ran `npm run format` and `npm run build` * ran `npm run update-installers` --- dist/cache-save/index.js | 9 ++++++--- dist/setup/index.js | 9 ++++++--- externals/install-dotnet.sh | 37 ++++++++++++++++++++++--------------- src/cache-utils.ts | 13 ++++++++++--- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 271b87a..8fdc7ad 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -81174,11 +81174,14 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /** * Returns this action runs on GitHub Enterprise Server or not. - * (port from https://github.com/actions/toolkit/blob/457303960f03375db6f033e214b9f90d79c3fe5c/packages/cache/src/internal/cacheUtils.ts#L134) */ function isGhes() { - const url = process.env['GITHUB_SERVER_URL'] || 'https://github.com'; - return new URL(url).hostname.toUpperCase() !== 'GITHUB.COM'; + const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); + const hostname = ghUrl.hostname.trimEnd().toUpperCase(); + const isGitHubHost = hostname === 'GITHUB.COM'; + const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM'); + const isLocalHost = hostname.endsWith('.LOCALHOST'); + return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost; } diff --git a/dist/setup/index.js b/dist/setup/index.js index 771ab51..b810e67 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -93633,11 +93633,14 @@ function isCacheFeatureAvailable() { exports.isCacheFeatureAvailable = isCacheFeatureAvailable; /** * Returns this action runs on GitHub Enterprise Server or not. - * (port from https://github.com/actions/toolkit/blob/457303960f03375db6f033e214b9f90d79c3fe5c/packages/cache/src/internal/cacheUtils.ts#L134) */ function isGhes() { - const url = process.env['GITHUB_SERVER_URL'] || 'https://github.com'; - return new URL(url).hostname.toUpperCase() !== 'GITHUB.COM'; + const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com'); + const hostname = ghUrl.hostname.trimEnd().toUpperCase(); + const isGitHubHost = hostname === 'GITHUB.COM'; + const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM'); + const isLocalHost = hostname.endsWith('.LOCALHOST'); + return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost; } diff --git a/externals/install-dotnet.sh b/externals/install-dotnet.sh index 38a160c..a64af37 100755 --- a/externals/install-dotnet.sh +++ b/externals/install-dotnet.sh @@ -423,11 +423,17 @@ get_normalized_architecture_for_specific_sdk_version() { # args: # version or channel - $1 is_arm64_supported() { - #any channel or version that starts with the specified versions - case "$1" in - ( "1"* | "2"* | "3"* | "4"* | "5"*) - echo false - return 0 + # Extract the major version by splitting on the dot + major_version="${1%%.*}" + + # Check if the major version is a valid number and less than 6 + case "$major_version" in + [0-9]*) + if [ "$major_version" -lt 6 ]; then + echo false + return 0 + fi + ;; esac echo true @@ -961,15 +967,16 @@ copy_files_or_dirs_from_list() { local root_path="$(remove_trailing_slash "$1")" local out_path="$(remove_trailing_slash "$2")" local override="$3" - local osname="$(get_current_os_name)" - local override_switch=$( - if [ "$override" = false ]; then - if [ "$osname" = "linux-musl" ]; then - printf -- "-u"; - else - printf -- "-n"; - fi - fi) + local override_switch="" + + if [ "$override" = false ]; then + override_switch="-n" + + # use -u instead of -n when it's available + if cp -u --help >/dev/null 2>&1; then + override_switch="-u" + fi + fi cat | uniq | while read -r file_path; do local path="$(remove_beginning_slash "${file_path#$root_path}")" @@ -1735,7 +1742,7 @@ do zip_path="$1" ;; -?|--?|-h|--help|-[Hh]elp) - script_name="$(basename "$0")" + script_name="dotnet-install.sh" echo ".NET Tools Installer" echo "Usage:" echo " # Install a .NET SDK of a given Quality from a given Channel" diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 4385da2..c487273 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -90,9 +90,16 @@ export function isCacheFeatureAvailable(): boolean { /** * Returns this action runs on GitHub Enterprise Server or not. - * (port from https://github.com/actions/toolkit/blob/457303960f03375db6f033e214b9f90d79c3fe5c/packages/cache/src/internal/cacheUtils.ts#L134) */ function isGhes(): boolean { - const url = process.env['GITHUB_SERVER_URL'] || 'https://github.com'; - return new URL(url).hostname.toUpperCase() !== 'GITHUB.COM'; + const ghUrl = new URL( + process.env['GITHUB_SERVER_URL'] || 'https://github.com' + ); + + const hostname = ghUrl.hostname.trimEnd().toUpperCase(); + const isGitHubHost = hostname === 'GITHUB.COM'; + const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM'); + const isLocalHost = hostname.endsWith('.LOCALHOST'); + + return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost; }