From 7e3178723ab9e083a52632761f742acdcd249e8b Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 8 Dec 2022 22:20:19 +0100 Subject: [PATCH] polish code --- dist/setup/index.js | 28 ++++++++++++++---------- src/installer.ts | 53 +++++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 806c1b1..7b0f1c4 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63236,17 +63236,7 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) { manifest = yield getManifest(auth); let stableVersion = yield resolveStableVersionInput(versionSpec, arch, osPlat, manifest); if (!stableVersion) { - let archFilter = sys.getArch(arch); - let platFilter = sys.getPlatform(); - const dlUrl = 'https://golang.org/dl/?mode=json&include=all'; - let candidates = yield module.exports.getVersionsDist(dlUrl); - if (!candidates) { - throw new Error(`golang download url did not return results`); - } - const fixedCandidates = candidates.map(item => { - return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) }); - }); - stableVersion = yield resolveStableVersionInput(versionSpec, archFilter, platFilter, fixedCandidates); + stableVersion = yield resolveStableVersionDist(versionSpec, arch); if (!stableVersion) { throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`); } @@ -63489,6 +63479,22 @@ function parseGoVersionFile(versionFilePath) { return contents.trim(); } exports.parseGoVersionFile = parseGoVersionFile; +function resolveStableVersionDist(versionSpec, arch) { + return __awaiter(this, void 0, void 0, function* () { + let archFilter = sys.getArch(arch); + let platFilter = sys.getPlatform(); + const dlUrl = 'https://golang.org/dl/?mode=json&include=all'; + let candidates = yield module.exports.getVersionsDist(dlUrl); + if (!candidates) { + throw new Error(`golang download url did not return results`); + } + const fixedCandidates = candidates.map(item => { + return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) }); + }); + const stableVersion = yield resolveStableVersionInput(versionSpec, archFilter, platFilter, fixedCandidates); + return stableVersion; + }); +} function resolveStableVersionInput(versionSpec, arch, platform, manifest) { return __awaiter(this, void 0, void 0, function* () { const releases = manifest diff --git a/src/installer.ts b/src/installer.ts index f6fda1c..3657447 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -52,30 +52,7 @@ export async function getGo( ); if (!stableVersion) { - let archFilter = sys.getArch(arch); - let platFilter = sys.getPlatform(); - const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all'; - let candidates: - | IGoVersion[] - | null = await module.exports.getVersionsDist(dlUrl); - if (!candidates) { - throw new Error(`golang download url did not return results`); - } - - const fixedCandidates = candidates.map(item => { - return { - ...item, - version: makeSemver(item.version) - }; - }); - - stableVersion = await resolveStableVersionInput( - versionSpec, - archFilter, - platFilter, - fixedCandidates - ); - + stableVersion = await resolveStableVersionDist(versionSpec, arch); if (!stableVersion) { throw new Error( `Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.` @@ -389,6 +366,34 @@ export function parseGoVersionFile(versionFilePath: string): string { return contents.trim(); } +async function resolveStableVersionDist(versionSpec: string, arch: string) { + let archFilter = sys.getArch(arch); + let platFilter = sys.getPlatform(); + const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all'; + let candidates: IGoVersion[] | null = await module.exports.getVersionsDist( + dlUrl + ); + if (!candidates) { + throw new Error(`golang download url did not return results`); + } + + const fixedCandidates = candidates.map(item => { + return { + ...item, + version: makeSemver(item.version) + }; + }); + + const stableVersion = await resolveStableVersionInput( + versionSpec, + archFilter, + platFilter, + fixedCandidates + ); + + return stableVersion; +} + export async function resolveStableVersionInput( versionSpec: string, arch: string,