From 91429219400902d711d2d1586234d708e8290a60 Mon Sep 17 00:00:00 2001 From: George Adams Date: Tue, 10 Mar 2026 18:08:36 +0000 Subject: [PATCH] skip json for known URL --- __tests__/setup-go.test.ts | 23 +++++------------------ dist/setup/index.js | 25 ++++++++++++++++++------- src/installer.ts | 28 ++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index a5eb16b..47f31fb 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -1141,7 +1141,7 @@ use . expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); }); - it('falls back to direct download when version listing is unavailable', async () => { + it('skips version listing for known direct-download URL (aka.ms)', async () => { os.platform = 'linux'; os.arch = 'x64'; @@ -1151,11 +1151,6 @@ use . inputs['go-version'] = versionSpec; inputs['go-download-base-url'] = customBaseUrl; - // Simulate JSON API not being available (like aka.ms) - getSpy.mockImplementationOnce(() => { - throw new Error('Not a JSON endpoint'); - }); - findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => '/some/temp/path'); const toolPath = path.normalize('/cache/go/1.25.0/x64'); @@ -1166,17 +1161,18 @@ use . const expPath = path.join(toolPath, 'bin'); expect(logSpy).toHaveBeenCalledWith( - 'Version listing not available from custom URL. Constructing download URL directly.' + 'Skipping version listing for known direct-download URL. Constructing download URL directly.' ); expect(logSpy).toHaveBeenCalledWith( `Constructed direct download URL: ${customBaseUrl}/go1.25.0.linux-amd64.tar.gz` ); expect(logSpy).toHaveBeenCalledWith('Install from custom download URL'); + expect(getSpy).not.toHaveBeenCalled(); expect(dlSpy).toHaveBeenCalled(); expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`); }); - it('constructs correct direct download URL for windows', async () => { + it('constructs correct direct download URL for windows (aka.ms)', async () => { os.platform = 'win32'; os.arch = 'x64'; @@ -1187,11 +1183,6 @@ use . inputs['go-download-base-url'] = customBaseUrl; process.env['RUNNER_TEMP'] = 'C:\\temp\\'; - // Simulate JSON API not being available - getSpy.mockImplementationOnce(() => { - throw new Error('Not a JSON endpoint'); - }); - findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => 'C:\\temp\\some\\path'); extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path'); @@ -1200,6 +1191,7 @@ use . await main.run(); + expect(getSpy).not.toHaveBeenCalled(); expect(dlSpy).toHaveBeenCalledWith( `${customBaseUrl}/go1.25.0.windows-amd64.zip`, 'C:\\temp\\go1.25.0.windows-amd64.zip', @@ -1409,11 +1401,6 @@ use . inputs['go-version'] = versionSpec; inputs['go-download-base-url'] = customBaseUrl; - // Simulate JSON API not being available (like aka.ms) - getSpy.mockImplementationOnce(() => { - throw new Error('Not a JSON endpoint'); - }); - findSpy.mockImplementation(() => ''); dlSpy.mockImplementation(async () => '/some/temp/path'); extractTarSpy.mockImplementation(async () => '/some/other/temp/path'); diff --git a/dist/setup/index.js b/dist/setup/index.js index eacc56b..b85fd2d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77063,6 +77063,10 @@ const MANIFEST_REPO_BRANCH = 'main'; const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`; const DEFAULT_GO_DOWNLOAD_BASE_URL = 'https://go.dev/dl'; const GOLANG_DOWNLOAD_URL = 'https://go.dev/dl/?mode=json&include=all'; +// Base URLs known to not serve a version listing JSON endpoint. +// For these URLs we skip the getInfoFromDist() call entirely and construct +// the download URL directly, avoiding a guaranteed-404 HTTP request. +const NO_VERSION_LISTING_BASE_URLS = ['https://aka.ms/golang/release/latest']; function getGo(versionSpec_1, checkLatest_1, auth_1) { return __awaiter(this, arguments, void 0, function* (versionSpec, checkLatest, auth, arch = os_1.default.arch(), goDownloadBaseUrl) { var _a; @@ -77120,15 +77124,22 @@ function getGo(versionSpec_1, checkLatest_1, auth_1) { // // Download from custom base URL // - try { - info = yield getInfoFromDist(versionSpec, arch, customBaseUrl); - } - catch (_b) { - core.info('Version listing not available from custom URL. Constructing download URL directly.'); - } - if (!info) { + const skipVersionListing = NO_VERSION_LISTING_BASE_URLS.some(url => customBaseUrl.toLowerCase() === url.toLowerCase()); + if (skipVersionListing) { + core.info('Skipping version listing for known direct-download URL. Constructing download URL directly.'); info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl); } + else { + try { + info = yield getInfoFromDist(versionSpec, arch, customBaseUrl); + } + catch (_b) { + core.info('Version listing not available from custom URL. Constructing download URL directly.'); + } + if (!info) { + info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl); + } + } try { core.info('Install from custom download URL'); downloadPath = yield installGoVersion(info, auth, arch, toolCacheName); diff --git a/src/installer.ts b/src/installer.ts index a4938c8..c1bab49 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -23,6 +23,11 @@ type InstallationType = 'dist' | 'manifest'; const GOLANG_DOWNLOAD_URL = 'https://go.dev/dl/?mode=json&include=all'; +// Base URLs known to not serve a version listing JSON endpoint. +// For these URLs we skip the getInfoFromDist() call entirely and construct +// the download URL directly, avoiding a guaranteed-404 HTTP request. +const NO_VERSION_LISTING_BASE_URLS = ['https://aka.ms/golang/release/latest']; + export interface IGoVersionFile { filename: string; // darwin, linux, windows @@ -132,15 +137,26 @@ export async function getGo( // // Download from custom base URL // - try { - info = await getInfoFromDist(versionSpec, arch, customBaseUrl); - } catch { + const skipVersionListing = NO_VERSION_LISTING_BASE_URLS.some( + url => customBaseUrl.toLowerCase() === url.toLowerCase() + ); + + if (skipVersionListing) { core.info( - 'Version listing not available from custom URL. Constructing download URL directly.' + 'Skipping version listing for known direct-download URL. Constructing download URL directly.' ); - } - if (!info) { info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl); + } else { + try { + info = await getInfoFromDist(versionSpec, arch, customBaseUrl); + } catch { + core.info( + 'Version listing not available from custom URL. Constructing download URL directly.' + ); + } + if (!info) { + info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl); + } } try {