mirror of
https://github.com/actions/setup-go.git
synced 2025-05-22 02:22:24 +00:00
another test and bugs
This commit is contained in:
@ -3,6 +3,7 @@ import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as httpm from '@actions/http-client';
|
||||
import * as sys from './system';
|
||||
import {debug} from '@actions/core';
|
||||
|
||||
export async function downloadGo(
|
||||
versionSpec: string,
|
||||
@ -12,24 +13,30 @@ export async function downloadGo(
|
||||
|
||||
try {
|
||||
let match: IGoVersion | undefined = await findMatch(versionSpec, stable);
|
||||
if (match) {
|
||||
console.log('match', match.version);
|
||||
}
|
||||
|
||||
if (match) {
|
||||
// download
|
||||
debug(`match ${match.version}`);
|
||||
let downloadUrl: string = `https://storage.googleapis.com/golang/${match.files[0].filename}`;
|
||||
let downloadPath: string = await tc.downloadTool(downloadUrl);
|
||||
debug(`downloaded to ${downloadPath}`);
|
||||
|
||||
// extract
|
||||
let extPath: string =
|
||||
sys.getPlatform() == 'windows'
|
||||
? await tc.extractZip(downloadPath)
|
||||
: await tc.extractTar(downloadPath);
|
||||
debug(`extracted to ${extPath}`);
|
||||
|
||||
// extracts with a root folder that matches the fileName downloaded
|
||||
const toolRoot = path.join(extPath, 'go');
|
||||
toolPath = await tc.cacheDir(toolRoot, 'go', versionSpec);
|
||||
}
|
||||
} catch (error) {
|
||||
throw `Failed to download version ${versionSpec}: ${error}`;
|
||||
throw new Error(`Failed to download version ${versionSpec}: ${error}`);
|
||||
}
|
||||
|
||||
return toolPath;
|
||||
@ -55,6 +62,7 @@ export async function findMatch(
|
||||
let archFilter = sys.getArch();
|
||||
let platFilter = sys.getPlatform();
|
||||
|
||||
let result: IGoVersion | undefined;
|
||||
let match: IGoVersion | undefined;
|
||||
|
||||
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
||||
@ -66,6 +74,7 @@ export async function findMatch(
|
||||
let goFile: IGoVersionFile | undefined;
|
||||
for (let i = 0; i < candidates.length; i++) {
|
||||
let candidate: IGoVersion = candidates[i];
|
||||
console.log(JSON.stringify(candidate, null, 2));
|
||||
let version = candidate.version.replace('go', '');
|
||||
|
||||
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
|
||||
@ -75,12 +84,15 @@ export async function findMatch(
|
||||
version = version + '.0';
|
||||
}
|
||||
|
||||
debug(`check ${version} satisfies ${versionSpec}`);
|
||||
if (semver.satisfies(version, versionSpec) && candidate.stable == stable) {
|
||||
goFile = candidate.files.find(file => {
|
||||
debug(`${file.arch}===${archFilter} && ${file.os}===${platFilter}`);
|
||||
return file.arch === archFilter && file.os === platFilter;
|
||||
});
|
||||
|
||||
if (goFile) {
|
||||
debug(`matched ${candidate.version}`);
|
||||
match = candidate;
|
||||
break;
|
||||
}
|
||||
@ -88,10 +100,12 @@ export async function findMatch(
|
||||
}
|
||||
|
||||
if (match && goFile) {
|
||||
match.files = [goFile];
|
||||
// clone since we're mutating the file list to be only the file that matches
|
||||
result = <IGoVersion>Object.assign({}, match);
|
||||
result.files = [goFile];
|
||||
}
|
||||
|
||||
return match;
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getVersions(dlUrl: string): Promise<IGoVersion[] | null> {
|
||||
|
Reference in New Issue
Block a user