From 11e0301e1d18c4a82bd0463b1a1c217d18b31638 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 8 Dec 2022 21:59:01 +0100 Subject: [PATCH 1/4] fix error with toolcache --- dist/setup/index.js | 26 +++++++++++------------ src/installer.ts | 52 +++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 6e16a2e..a494179 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63234,7 +63234,18 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) { if (versionSpec === utils_1.StableReleaseAlias.Stable || versionSpec === utils_1.StableReleaseAlias.OldStable) { manifest = yield getManifest(auth); - versionSpec = yield resolveStableVersionInput(versionSpec, arch, osPlat, manifest); + let stableVersion = yield resolveStableVersionInput(versionSpec, arch, osPlat, manifest); + if (!stableVersion) { + 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, arch, osPlat, fixedCandidates); + } } if (checkLatest) { core.info('Attempting to resolve the latest version from the manifest...'); @@ -63400,13 +63411,6 @@ function findMatch(versionSpec, arch = os_1.default.arch()) { if (!candidates) { throw new Error(`golang download url did not return results`); } - if (versionSpec === utils_1.StableReleaseAlias.Stable || - versionSpec === utils_1.StableReleaseAlias.OldStable) { - const fixedCandidates = candidates.map(item => { - return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) }); - }); - versionSpec = yield resolveStableVersionInput(versionSpec, archFilter, platFilter, fixedCandidates); - } let goFile; for (let i = 0; i < candidates.length; i++) { let candidate = candidates[i]; @@ -63480,7 +63484,6 @@ function parseGoVersionFile(versionFilePath) { } exports.parseGoVersionFile = parseGoVersionFile; function resolveStableVersionInput(versionSpec, arch, platform, manifest) { - var _a; return __awaiter(this, void 0, void 0, function* () { const releases = manifest .map(item => { @@ -63493,16 +63496,13 @@ function resolveStableVersionInput(versionSpec, arch, platform, manifest) { .filter(item => !!item && !semver.prerelease(item)); if (versionSpec === utils_1.StableReleaseAlias.Stable) { core.info(`stable version resolved as ${releases[0]}`); - return (_a = releases[0]) !== null && _a !== void 0 ? _a : versionSpec; + return releases[0]; } else { const versions = releases.map(release => `${semver.major(release)}.${semver.minor(release)}`); const uniqueVersions = Array.from(new Set(versions)); const oldstableVersion = releases.find(item => item.startsWith(uniqueVersions[1])); core.info(`oldstable version resolved as ${oldstableVersion}`); - if (!oldstableVersion) { - return versionSpec; - } return oldstableVersion; } }); diff --git a/src/installer.ts b/src/installer.ts index 9be22a9..acea2ba 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -44,12 +44,36 @@ export async function getGo( versionSpec === StableReleaseAlias.OldStable ) { manifest = await getManifest(auth); - versionSpec = await resolveStableVersionInput( + let stableVersion = await resolveStableVersionInput( versionSpec, arch, osPlat, manifest ); + + if (!stableVersion) { + 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, + arch, + osPlat, + fixedCandidates + ); + } } if (checkLatest) { @@ -267,24 +291,6 @@ export async function findMatch( throw new Error(`golang download url did not return results`); } - if ( - versionSpec === StableReleaseAlias.Stable || - versionSpec === StableReleaseAlias.OldStable - ) { - const fixedCandidates = candidates.map(item => { - return { - ...item, - version: makeSemver(item.version) - }; - }); - versionSpec = await resolveStableVersionInput( - versionSpec, - archFilter, - platFilter, - fixedCandidates - ); - } - let goFile: IGoVersionFile | undefined; for (let i = 0; i < candidates.length; i++) { let candidate: IGoVersion = candidates[i]; @@ -378,7 +384,7 @@ export async function resolveStableVersionInput( arch: string, platform: string, manifest: tc.IToolRelease[] | IGoVersion[] -): Promise { +) { const releases = manifest .map(item => { const index = item.files.findIndex( @@ -394,7 +400,7 @@ export async function resolveStableVersionInput( if (versionSpec === StableReleaseAlias.Stable) { core.info(`stable version resolved as ${releases[0]}`); - return releases[0] ?? versionSpec; + return releases[0]; } else { const versions = releases.map( release => `${semver.major(release)}.${semver.minor(release)}` @@ -407,10 +413,6 @@ export async function resolveStableVersionInput( core.info(`oldstable version resolved as ${oldstableVersion}`); - if (!oldstableVersion) { - return versionSpec; - } - return oldstableVersion; } } From 5a5cdc8151239e38aa97416025497a8c1460f31f Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 8 Dec 2022 22:10:41 +0100 Subject: [PATCH 2/4] minor fix --- dist/setup/index.js | 8 +++++++- src/installer.ts | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index a494179..806c1b1 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63236,6 +63236,8 @@ 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) { @@ -63244,8 +63246,12 @@ function getGo(versionSpec, checkLatest, auth, arch = os_1.default.arch()) { const fixedCandidates = candidates.map(item => { return Object.assign(Object.assign({}, item), { version: makeSemver(item.version) }); }); - stableVersion = yield resolveStableVersionInput(versionSpec, arch, osPlat, fixedCandidates); + stableVersion = yield resolveStableVersionInput(versionSpec, archFilter, platFilter, fixedCandidates); + if (!stableVersion) { + throw new Error(`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`); + } } + versionSpec = stableVersion; } if (checkLatest) { core.info('Attempting to resolve the latest version from the manifest...'); diff --git a/src/installer.ts b/src/installer.ts index acea2ba..f6fda1c 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -52,6 +52,8 @@ 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[] @@ -69,11 +71,19 @@ export async function getGo( stableVersion = await resolveStableVersionInput( versionSpec, - arch, - osPlat, + archFilter, + platFilter, fixedCandidates ); + + if (!stableVersion) { + throw new Error( + `Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.` + ); + } } + + versionSpec = stableVersion; } if (checkLatest) { From 7e3178723ab9e083a52632761f742acdcd249e8b Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Thu, 8 Dec 2022 22:20:19 +0100 Subject: [PATCH 3/4] 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, From 7cf57d7094bd25d126f6577c104c2e5b72284034 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Fri, 9 Dec 2022 01:23:08 +0100 Subject: [PATCH 4/4] add job aliases with different arch --- .github/workflows/versions.yml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/versions.yml b/.github/workflows/versions.yml index 1291b08..95d1b6a 100644 --- a/.github/workflows/versions.yml +++ b/.github/workflows/versions.yml @@ -20,7 +20,7 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v3 - - name: Setup Go and check latest + - name: Setup Go Stable uses: ./ with: go-version: stable @@ -35,12 +35,33 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] steps: - uses: actions/checkout@v3 - - name: Setup Go and check latest + - name: Setup Go oldStable uses: ./ with: go-version: oldstable - name: Verify Go run: go version + + aliases-arch: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + version: [stable, oldstable] + architecture: [x64, x32] + exclude: + - os: macos-latest + architecture: x32 + steps: + - uses: actions/checkout@v3 + - name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }} + uses: ./ + with: + go-version: ${{ matrix.version }} + architecture: ${{ matrix.architecture }} + - name: Verify Go + run: go version local-cache: name: Setup local-cache version