From 7f7ac4097738db1c7e654634c23e4c627fdcd5d0 Mon Sep 17 00:00:00 2001 From: John Wesley Walker III <81404201+jww3@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:26:13 +0200 Subject: [PATCH] Revise `isGhes` logic --- src/cache-utils.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 4385da2..db782be 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'; +export function isGhes(): boolean { + 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 }