Skip to content

Commit

Permalink
Cannot reuse IGoVersionInfo from dist for manifest
Browse files Browse the repository at this point in the history
...and vice versa.

While here, also free versionInfo and versionSpec so we don't
(un)intentionally overwrite them somewhere down below.
  • Loading branch information
bdd committed Sep 16, 2020
1 parent 9333ae6 commit 2134aea
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
26 changes: 24 additions & 2 deletions dist/index.js
Expand Up @@ -4973,6 +4973,9 @@ function getGo(versionSpec, versionSpecResolver, stable, auth) {
}
if (versionInfo && versionInfo.resolvedVersion.length > 0) {
versionSpec = versionInfo.resolvedVersion;
// Freeze these to protect (un)intentional overwrites.
Object.freeze(versionInfo);
Object.freeze(versionSpec);
}
// check cache
let toolPath;
Expand All @@ -4989,7 +4992,18 @@ function getGo(versionSpec, versionSpecResolver, stable, auth) {
// Try download from internal distribution (popular versions only)
//
try {
info = versionInfo !== null && versionInfo !== void 0 ? versionInfo : (yield getInfoFromManifest(versionSpec, stable, auth));
if ((versionInfo === null || versionInfo === void 0 ? void 0 : versionInfo.type) == 'manifest') {
info = versionInfo;
}
else {
// The version search in the cache was a miss. We either have no previous
// explicit version resolution attempt or it came from 'dist' version registry
// and have an `downloadUrl` pointing to an external resource.
//
// Check the @actions/go-versions manifest with current `versionSpec`; either
// an explicit one or a semver range.
info = yield getInfoFromManifest(versionSpec, stable, auth);
}
if (info) {
downloadPath = yield installGoVersion(info, auth);
}
Expand All @@ -5012,7 +5026,15 @@ function getGo(versionSpec, versionSpecResolver, stable, auth) {
// Download from storage.googleapis.com
//
if (!downloadPath) {
info = versionInfo !== null && versionInfo !== void 0 ? versionInfo : (yield getInfoFromDist(versionSpec, stable));
if ((versionInfo === null || versionInfo === void 0 ? void 0 : versionInfo.type) == 'dist') {
info = versionInfo;
}
else {
// Version search didn't match anything available in the cache or @actions/go-versions.
// We either have no previous explicit version resolution attempt or downloading from
// @actions/go-versions manifest specified URL somehow failed.
info = yield getInfoFromDist(versionSpec, stable);
}
if (!info) {
let osPlat = os_1.default.platform();
let osArch = os_1.default.arch();
Expand Down
28 changes: 25 additions & 3 deletions src/installer.ts
Expand Up @@ -53,6 +53,10 @@ export async function getGo(

if (versionInfo && versionInfo.resolvedVersion.length > 0) {
versionSpec = versionInfo.resolvedVersion;

// Freeze these to protect (un)intentional overwrites.
Object.freeze(versionInfo);
Object.freeze(versionSpec);
}

// check cache
Expand All @@ -71,8 +75,18 @@ export async function getGo(
// Try download from internal distribution (popular versions only)
//
try {
info =
versionInfo ?? (await getInfoFromManifest(versionSpec, stable, auth));
if (versionInfo?.type == 'manifest') {
info = versionInfo;
} else {
// The version search in the cache was a miss. We either have no previous
// explicit version resolution attempt or it came from 'dist' version registry
// and have an `downloadUrl` pointing to an external resource.
//
// Check the @actions/go-versions manifest with current `versionSpec`; either
// an explicit one or a semver range.
info = await getInfoFromManifest(versionSpec, stable, auth);
}

if (info) {
downloadPath = await installGoVersion(info, auth);
} else {
Expand All @@ -99,7 +113,15 @@ export async function getGo(
// Download from storage.googleapis.com
//
if (!downloadPath) {
info = versionInfo ?? (await getInfoFromDist(versionSpec, stable));
if (versionInfo?.type == 'dist') {
info = versionInfo;
} else {
// Version search didn't match anything available in the cache or @actions/go-versions.
// We either have no previous explicit version resolution attempt or downloading from
// @actions/go-versions manifest specified URL somehow failed.
info = await getInfoFromDist(versionSpec, stable);
}

if (!info) {
let osPlat: string = os.platform();
let osArch: string = os.arch();
Expand Down

0 comments on commit 2134aea

Please sign in to comment.