From fa731dd19efc9a985de749698cba9d3e9bb6b87d Mon Sep 17 00:00:00 2001 From: alphachart <89230871+alphachart@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:19:25 +0330 Subject: [PATCH] Revert "Refine `isGhes` logic (#697)" This reverts commit 8df1039502a15bceb9433410b1a100fbe190c53b. --- __tests__/util.test.ts | 41 +---------------------------------------- dist/cleanup/index.js | 6 +----- dist/setup/index.js | 6 +----- src/util.ts | 8 +------- 4 files changed, 4 insertions(+), 57 deletions(-) diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index 9c943c2f..bb7560dc 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -3,8 +3,7 @@ import * as core from '@actions/core'; import { convertVersionToSemver, isVersionSatisfies, - isCacheFeatureAvailable, - isGhes + isCacheFeatureAvailable } from '../src/util'; jest.mock('@actions/cache'); @@ -81,41 +80,3 @@ describe('convertVersionToSemver', () => { expect(actual).toBe(expected); }); }); - -describe('isGhes', () => { - const pristineEnv = process.env; - - beforeEach(() => { - jest.resetModules(); - process.env = {...pristineEnv}; - }); - - afterAll(() => { - process.env = pristineEnv; - }); - - it('returns false when the GITHUB_SERVER_URL environment variable is not defined', async () => { - delete process.env['GITHUB_SERVER_URL']; - expect(isGhes()).toBeFalsy(); - }); - - it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', async () => { - process.env['GITHUB_SERVER_URL'] = 'https://github.com'; - expect(isGhes()).toBeFalsy(); - }); - - it('returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL', async () => { - process.env['GITHUB_SERVER_URL'] = 'https://contoso.ghe.com'; - expect(isGhes()).toBeFalsy(); - }); - - it('returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix', async () => { - process.env['GITHUB_SERVER_URL'] = 'https://mock-github.localhost'; - expect(isGhes()).toBeFalsy(); - }); - - it('returns true when the GITHUB_SERVER_URL environment variable is set to some other URL', async () => { - process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com'; - expect(isGhes()).toBeTruthy(); - }); -}); diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 6c44aa45..5a200909 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -88552,11 +88552,7 @@ function isJobStatusSuccess() { exports.isJobStatusSuccess = isJobStatusSuccess; function isGhes() { 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; + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } exports.isGhes = isGhes; function isCacheFeatureAvailable() { diff --git a/dist/setup/index.js b/dist/setup/index.js index 9dc658d8..e96bb125 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -126328,11 +126328,7 @@ function isJobStatusSuccess() { exports.isJobStatusSuccess = isJobStatusSuccess; function isGhes() { 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; + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } exports.isGhes = isGhes; function isCacheFeatureAvailable() { diff --git a/src/util.ts b/src/util.ts index af75aaac..c0166ef1 100644 --- a/src/util.ts +++ b/src/util.ts @@ -92,13 +92,7 @@ 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; + return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } export function isCacheFeatureAvailable(): boolean {