diff --git a/packages/artifact/__tests__/config.test.ts b/packages/artifact/__tests__/config.test.ts index 3d14ace2b2..7d3be228e0 100644 --- a/packages/artifact/__tests__/config.test.ts +++ b/packages/artifact/__tests__/config.test.ts @@ -15,6 +15,11 @@ beforeEach(() => { }) describe('isGhes', () => { + beforeEach(() => { + delete process.env.GITHUB_SERVER_URL + delete process.env.ACTIONS_RESULTS_URL + }) + it('should return false when the request domain is github.com', () => { process.env.GITHUB_SERVER_URL = 'https://github.com' expect(config.isGhes()).toBe(false) @@ -35,10 +40,22 @@ describe('isGhes', () => { expect(config.isGhes()).toBe(false) }) - it('should return false when the request domain is specific to an enterprise', () => { + it('should return true on a self-hosted enterprise hostname when ACTIONS_RESULTS_URL is unset', () => { process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com' expect(config.isGhes()).toBe(true) }) + + it('should return false on a self-hosted enterprise hostname when ACTIONS_RESULTS_URL is set (v2 backend available)', () => { + process.env.GITHUB_SERVER_URL = 'https://my-enterprise.github.com' + process.env.ACTIONS_RESULTS_URL = 'https://results.example.com/' + expect(config.isGhes()).toBe(false) + }) + + it('should ignore ACTIONS_RESULTS_URL on github.com (already returns false there)', () => { + process.env.GITHUB_SERVER_URL = 'https://github.com' + process.env.ACTIONS_RESULTS_URL = 'https://results.example.com/' + expect(config.isGhes()).toBe(false) + }) }) describe('uploadChunkTimeoutEnv', () => { diff --git a/packages/artifact/src/internal/shared/config.ts b/packages/artifact/src/internal/shared/config.ts index 0a275fd5ee..2991f69f8e 100644 --- a/packages/artifact/src/internal/shared/config.ts +++ b/packages/artifact/src/internal/shared/config.ts @@ -34,7 +34,21 @@ export function isGhes(): boolean { const isGheHost = hostname.endsWith('.GHE.COM') const isLocalHost = hostname.endsWith('.LOCALHOST') - return !isGitHubHost && !isGheHost && !isLocalHost + const hostnameLooksLikeGhes = + !isGitHubHost && !isGheHost && !isLocalHost + + // GHES 3.13+ ships the artifact-storage-v2 backend that the v4+ + // artifact client requires. The runner exposes the backend's + // presence via ACTIONS_RESULTS_URL (which getResultsServiceUrl() + // already requires for upload/download/list to function). When + // that env var is set we know the backend is reachable, so an + // unrecognised hostname does not need to short-circuit into a + // GHESNotSupportedError. + if (hostnameLooksLikeGhes && process.env['ACTIONS_RESULTS_URL']) { + return false + } + + return hostnameLooksLikeGhes } export function getGitHubWorkspaceDir(): string {