Skip to content

Commit 3e891b0

Browse files
authored
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`
1 parent 2e0b259 commit 3e891b0

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

dist/cache-save/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -81174,11 +81174,14 @@ function isCacheFeatureAvailable() {
8117481174
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
8117581175
/**
8117681176
* Returns this action runs on GitHub Enterprise Server or not.
81177-
* (port from https://github.com/actions/toolkit/blob/457303960f03375db6f033e214b9f90d79c3fe5c/packages/cache/src/internal/cacheUtils.ts#L134)
8117881177
*/
8117981178
function isGhes() {
81180-
const url = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
81181-
return new URL(url).hostname.toUpperCase() !== 'GITHUB.COM';
81179+
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
81180+
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
81181+
const isGitHubHost = hostname === 'GITHUB.COM';
81182+
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
81183+
const isLocalHost = hostname.endsWith('.LOCALHOST');
81184+
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
8118281185
}
8118381186

8118481187

dist/setup/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -93633,11 +93633,14 @@ function isCacheFeatureAvailable() {
9363393633
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
9363493634
/**
9363593635
* Returns this action runs on GitHub Enterprise Server or not.
93636-
* (port from https://github.com/actions/toolkit/blob/457303960f03375db6f033e214b9f90d79c3fe5c/packages/cache/src/internal/cacheUtils.ts#L134)
9363793636
*/
9363893637
function isGhes() {
93639-
const url = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
93640-
return new URL(url).hostname.toUpperCase() !== 'GITHUB.COM';
93638+
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
93639+
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
93640+
const isGitHubHost = hostname === 'GITHUB.COM';
93641+
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
93642+
const isLocalHost = hostname.endsWith('.LOCALHOST');
93643+
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
9364193644
}
9364293645

9364393646

externals/install-dotnet.sh

+22-15
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,17 @@ get_normalized_architecture_for_specific_sdk_version() {
423423
# args:
424424
# version or channel - $1
425425
is_arm64_supported() {
426-
#any channel or version that starts with the specified versions
427-
case "$1" in
428-
( "1"* | "2"* | "3"* | "4"* | "5"*)
429-
echo false
430-
return 0
426+
# Extract the major version by splitting on the dot
427+
major_version="${1%%.*}"
428+
429+
# Check if the major version is a valid number and less than 6
430+
case "$major_version" in
431+
[0-9]*)
432+
if [ "$major_version" -lt 6 ]; then
433+
echo false
434+
return 0
435+
fi
436+
;;
431437
esac
432438

433439
echo true
@@ -961,15 +967,16 @@ copy_files_or_dirs_from_list() {
961967
local root_path="$(remove_trailing_slash "$1")"
962968
local out_path="$(remove_trailing_slash "$2")"
963969
local override="$3"
964-
local osname="$(get_current_os_name)"
965-
local override_switch=$(
966-
if [ "$override" = false ]; then
967-
if [ "$osname" = "linux-musl" ]; then
968-
printf -- "-u";
969-
else
970-
printf -- "-n";
971-
fi
972-
fi)
970+
local override_switch=""
971+
972+
if [ "$override" = false ]; then
973+
override_switch="-n"
974+
975+
# use -u instead of -n when it's available
976+
if cp -u --help >/dev/null 2>&1; then
977+
override_switch="-u"
978+
fi
979+
fi
973980

974981
cat | uniq | while read -r file_path; do
975982
local path="$(remove_beginning_slash "${file_path#$root_path}")"
@@ -1735,7 +1742,7 @@ do
17351742
zip_path="$1"
17361743
;;
17371744
-?|--?|-h|--help|-[Hh]elp)
1738-
script_name="$(basename "$0")"
1745+
script_name="dotnet-install.sh"
17391746
echo ".NET Tools Installer"
17401747
echo "Usage:"
17411748
echo " # Install a .NET SDK of a given Quality from a given Channel"

src/cache-utils.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,16 @@ export function isCacheFeatureAvailable(): boolean {
9090

9191
/**
9292
* Returns this action runs on GitHub Enterprise Server or not.
93-
* (port from https://github.com/actions/toolkit/blob/457303960f03375db6f033e214b9f90d79c3fe5c/packages/cache/src/internal/cacheUtils.ts#L134)
9493
*/
9594
function isGhes(): boolean {
96-
const url = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
97-
return new URL(url).hostname.toUpperCase() !== 'GITHUB.COM';
95+
const ghUrl = new URL(
96+
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
97+
);
98+
99+
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
100+
const isGitHubHost = hostname === 'GITHUB.COM';
101+
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
102+
const isLocalHost = hostname.endsWith('.LOCALHOST');
103+
104+
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
98105
}

0 commit comments

Comments
 (0)