Revise isGhes logic (#1148)
Some checks failed
Basic validation / Basic validation (push) Failing after -1m17s
Check dist / Check dist/ (push) Failing after 0s
CodeQL analysis / CodeQL analysis (push) Failing after -1m17s
Licensed / Licensed (push) Failing after 0s
versions / rc-syntax (18.0.0-rc.2, ubuntu-latest) (push) Has been cancelled
versions / rc-syntax (18.0.0-rc.2, windows-latest) (push) Has been cancelled
versions / manifest (22.0.0, ubuntu-latest) (push) Has been cancelled
versions / manifest (22.0.0, windows-latest) (push) Has been cancelled
versions / version-file (.nvmrc, ubuntu-latest) (push) Has been cancelled
versions / check-latest (18, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/dubnium, ubuntu-latest) (push) Has been cancelled
versions / lts-syntax (lts/dubnium, windows-latest) (push) Has been cancelled
versions / version-file (.nvmrc, windows-latest) (push) Has been cancelled
versions / node-dist (17, macos-latest) (push) Has been cancelled
versions / arch (push) Has been cancelled
versions / check-latest (18, ubuntu-latest) (push) Has been cancelled
versions / rc-syntax (19.0.0-rc.0, macos-latest) (push) Has been cancelled
versions / rc-syntax (19.0.0-rc.0, ubuntu-latest) (push) Has been cancelled
versions / rc-syntax (19.0.0-rc.0, windows-latest) (push) Has been cancelled
versions / rc-syntax (20.0.0-rc.1, macos-latest) (push) Has been cancelled
versions / version-file (.nvmrc, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/erbium, macos-13) (push) Has been cancelled
versions / rc-syntax (20.0.0-rc.1, ubuntu-latest) (push) Has been cancelled
versions / lts-syntax (lts/erbium, ubuntu-latest) (push) Has been cancelled
versions / rc-syntax (20.0.0-rc.1, windows-latest) (push) Has been cancelled
versions / manifest (18.20.0, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/erbium, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/fermium, macos-13) (push) Has been cancelled
versions / manifest (18.20.0, ubuntu-latest) (push) Has been cancelled
versions / manifest (18.20.0, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/fermium, ubuntu-latest) (push) Has been cancelled
versions / manifest (20.10.0, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 18, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 18, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 18, windows-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 20, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 20, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 20, windows-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 22, macos-latest) (push) Has been cancelled
versions / manifest (20.10.0, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 22, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test npm (Node 22, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 18, macos-latest) (push) Has been cancelled
versions / manifest (20.10.0, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 18, ubuntu-latest) (push) Has been cancelled
versions / lts-syntax (lts/fermium, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 18, windows-latest) (push) Has been cancelled
versions / v8-canary-syntax (20-v8-canary, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 20, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 20, ubuntu-latest) (push) Has been cancelled
versions / v8-canary-syntax (20-v8-canary, ubuntu-latest) (push) Has been cancelled
versions / v8-canary-syntax (20-v8-canary, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 20, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 22, macos-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 22, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node 22, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 18, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 18, ubuntu-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 18, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 20, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 20, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node 20, windows-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 18, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 18, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 18, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 20, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 20, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 20, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 22, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 22, ubuntu-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node 22, windows-latest) (push) Has been cancelled
versions / rc-syntax (18.0.0-rc.2, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/*, ubuntu-latest) (push) Has been cancelled
versions / manifest (22.0.0, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/*, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/-1, macos-13) (push) Has been cancelled
versions / lts-syntax (lts/-1, ubuntu-latest) (push) Has been cancelled
versions / lts-syntax (lts/-1, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/dubnium, macos-13) (push) Has been cancelled
e2e-cache / Test yarn subprojects (push) Has been cancelled
e2e-cache / Test yarn subprojects all locally managed (push) Has been cancelled
e2e-cache / Test yarn subprojects some locally managed (push) Has been cancelled
e2e-cache / Test yarn subprojects managed by git (push) Has been cancelled
proxy / test-proxy (push) Has been cancelled
proxy / test-bypass-proxy (push) Has been cancelled
versions / local-cache (18, macos-latest) (push) Has been cancelled
versions / local-cache (18, ubuntu-latest) (push) Has been cancelled
versions / local-cache (18, windows-latest) (push) Has been cancelled
versions / local-cache (20, macos-latest) (push) Has been cancelled
versions / local-cache (20, ubuntu-latest) (push) Has been cancelled
versions / local-cache (20, windows-latest) (push) Has been cancelled
versions / local-cache (22, macos-latest) (push) Has been cancelled
versions / local-cache (22, ubuntu-latest) (push) Has been cancelled
versions / local-cache (22, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/*, macos-13) (push) Has been cancelled
versions / nightly-syntax (21-nightly, macos-latest) (push) Has been cancelled
versions / nightly-syntax (21-nightly, ubuntu-latest) (push) Has been cancelled
versions / nightly-syntax (21-nightly, windows-latest) (push) Has been cancelled
versions / check-latest (18, windows-latest) (push) Has been cancelled
versions / check-latest (20, macos-latest) (push) Has been cancelled
versions / check-latest (20, ubuntu-latest) (push) Has been cancelled
versions / check-latest (20, windows-latest) (push) Has been cancelled
versions / check-latest (22, macos-latest) (push) Has been cancelled
versions / check-latest (22, ubuntu-latest) (push) Has been cancelled
versions / check-latest (22, windows-latest) (push) Has been cancelled
versions / version-file (.tool-versions, macos-latest) (push) Has been cancelled
versions / version-file (.tool-versions, ubuntu-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, macos-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, ubuntu-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, windows-latest) (push) Has been cancelled
versions / nightly-syntax (18.0.0-nightly, macos-latest) (push) Has been cancelled
versions / nightly-syntax (18.0.0-nightly, ubuntu-latest) (push) Has been cancelled
versions / nightly-syntax (18.0.0-nightly, windows-latest) (push) Has been cancelled
versions / nightly-syntax (20.11.0-nightly202312211a0be537da, macos-latest) (push) Has been cancelled
versions / nightly-syntax (20.11.0-nightly202312211a0be537da, ubuntu-latest) (push) Has been cancelled
versions / nightly-syntax (20.11.0-nightly202312211a0be537da, windows-latest) (push) Has been cancelled
versions / version-file (package.json, windows-latest) (push) Has been cancelled
versions / version-file-volta (macos-latest) (push) Has been cancelled
versions / version-file-volta (ubuntu-latest) (push) Has been cancelled
versions / version-file-volta (windows-latest) (push) Has been cancelled
versions / version-file-volta-extends (macos-latest) (push) Has been cancelled
versions / version-file-volta-extends (ubuntu-latest) (push) Has been cancelled
versions / version-file-volta-extends (windows-latest) (push) Has been cancelled
versions / node-dist (17, ubuntu-latest) (push) Has been cancelled
versions / node-dist (17, windows-latest) (push) Has been cancelled
versions / node-dist (19, macos-latest) (push) Has been cancelled
versions / node-dist (19, ubuntu-latest) (push) Has been cancelled
versions / node-dist (19, windows-latest) (push) Has been cancelled
versions / old-versions (macos-13) (push) Has been cancelled
versions / old-versions (ubuntu-latest) (push) Has been cancelled
versions / old-versions (windows-latest) (push) Has been cancelled
versions / node-latest-aliases (current, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (current, ubuntu-latest) (push) Has been cancelled
versions / node-latest-aliases (current, windows-latest) (push) Has been cancelled
versions / version-file (.tool-versions, windows-latest) (push) Has been cancelled
versions / version-file (.tool-versions-node, macos-latest) (push) Has been cancelled
versions / version-file (.tool-versions-node, ubuntu-latest) (push) Has been cancelled
versions / version-file (.tool-versions-node, windows-latest) (push) Has been cancelled
versions / version-file (package.json, macos-latest) (push) Has been cancelled
versions / version-file (package.json, ubuntu-latest) (push) Has been cancelled
versions / node-latest-aliases (latest, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (latest, ubuntu-latest) (push) Has been cancelled
versions / node-latest-aliases (latest, windows-latest) (push) Has been cancelled
versions / node-latest-aliases (node, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (node, ubuntu-latest) (push) Has been cancelled
versions / node-latest-aliases (node, windows-latest) (push) Has been cancelled

* Revise `isGhes` logic

* ran 'npm run format'

* added unit test
This commit is contained in:
John Wesley Walker III 2024-10-21 18:41:32 +02:00 committed by GitHub
parent aca7b64a59
commit abb238b131
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 56 additions and 4 deletions

View file

@ -6,7 +6,7 @@ import {
PackageManagerInfo,
isCacheFeatureAvailable,
supportedPackageManagers,
getCommandOutput,
isGhes,
resetProjectDirectoriesMemoized
} from '../src/cache-utils';
import fs from 'fs';
@ -361,3 +361,41 @@ describe('cache-utils', () => {
);
});
});
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', () => {
delete process.env['GITHUB_SERVER_URL'];
expect(isGhes()).toBeFalsy();
});
it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', () => {
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', () => {
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', () => {
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', () => {
process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com';
expect(isGhes()).toBeTruthy();
});
});

View file

@ -83977,7 +83977,11 @@ const repoHasYarnBerryManagedDependencies = (packageManagerInfo, cacheDependency
exports.repoHasYarnBerryManagedDependencies = repoHasYarnBerryManagedDependencies;
function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
return ghUrl.hostname.toUpperCase() !== '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;
}
exports.isGhes = isGhes;
function isCacheFeatureAvailable() {

6
dist/setup/index.js vendored
View file

@ -93598,7 +93598,11 @@ const repoHasYarnBerryManagedDependencies = (packageManagerInfo, cacheDependency
exports.repoHasYarnBerryManagedDependencies = repoHasYarnBerryManagedDependencies;
function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
return ghUrl.hostname.toUpperCase() !== '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;
}
exports.isGhes = isGhes;
function isCacheFeatureAvailable() {

View file

@ -295,7 +295,13 @@ export function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
);
return ghUrl.hostname.toUpperCase() !== '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;
}
export function isCacheFeatureAvailable(): boolean {