mirror of
https://github.com/actions/setup-go.git
synced 2026-03-14 14:45:45 +01:00
skip json for known URL
This commit is contained in:
parent
fa4cd7679b
commit
9142921940
3 changed files with 45 additions and 31 deletions
|
|
@ -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');
|
||||
|
|
|
|||
25
dist/setup/index.js
vendored
25
dist/setup/index.js
vendored
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue