|
|
|
@ -1,10 +1,13 @@
|
|
|
|
|
import * as tc from '@actions/tool-cache';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
import * as semver from 'semver';
|
|
|
|
|
import * as httpm from '@actions/http-client'
|
|
|
|
|
import * as sys from './system'
|
|
|
|
|
import * as httpm from '@actions/http-client';
|
|
|
|
|
import * as sys from './system';
|
|
|
|
|
|
|
|
|
|
export async function downloadGo(versionSpec: string, stable: boolean): Promise<string | undefined> {
|
|
|
|
|
export async function downloadGo(
|
|
|
|
|
versionSpec: string,
|
|
|
|
|
stable: boolean
|
|
|
|
|
): Promise<string | undefined> {
|
|
|
|
|
let toolPath: string | undefined;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -16,8 +19,10 @@ export async function downloadGo(versionSpec: string, stable: boolean): Promise<
|
|
|
|
|
let downloadPath: string = await tc.downloadTool(downloadUrl);
|
|
|
|
|
|
|
|
|
|
// extract
|
|
|
|
|
let extPath: string = sys.getPlatform() == 'windows'?
|
|
|
|
|
await tc.extractZip(downloadPath): await tc.extractTar(downloadPath);
|
|
|
|
|
let extPath: string =
|
|
|
|
|
sys.getPlatform() == 'windows'
|
|
|
|
|
? await tc.extractZip(downloadPath)
|
|
|
|
|
: await tc.extractTar(downloadPath);
|
|
|
|
|
|
|
|
|
|
// extracts with a root folder that matches the fileName downloaded
|
|
|
|
|
const toolRoot = path.join(extPath, 'go');
|
|
|
|
@ -31,10 +36,10 @@ export async function downloadGo(versionSpec: string, stable: boolean): Promise<
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface IGoVersionFile {
|
|
|
|
|
filename: string,
|
|
|
|
|
filename: string;
|
|
|
|
|
// darwin, linux, windows
|
|
|
|
|
os: string,
|
|
|
|
|
arch: string
|
|
|
|
|
os: string;
|
|
|
|
|
arch: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface IGoVersion {
|
|
|
|
@ -43,7 +48,10 @@ export interface IGoVersion {
|
|
|
|
|
files: IGoVersionFile[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function findMatch(versionSpec: string, stable: boolean): Promise<IGoVersion | undefined> {
|
|
|
|
|
export async function findMatch(
|
|
|
|
|
versionSpec: string,
|
|
|
|
|
stable: boolean
|
|
|
|
|
): Promise<IGoVersion | undefined> {
|
|
|
|
|
let archFilter = sys.getArch();
|
|
|
|
|
let platFilter = sys.getPlatform();
|
|
|
|
|
|
|
|
|
@ -52,7 +60,9 @@ export async function findMatch(versionSpec: string, stable: boolean): Promise<I
|
|
|
|
|
|
|
|
|
|
// this returns versions descending so latest is first
|
|
|
|
|
let http: httpm.HttpClient = new httpm.HttpClient('setup-go');
|
|
|
|
|
let candidates: IGoVersion[] | null = (await http.getJson<IGoVersion[]>(dlUrl)).result;
|
|
|
|
|
let candidates: IGoVersion[] | null = (await http.getJson<IGoVersion[]>(
|
|
|
|
|
dlUrl
|
|
|
|
|
)).result;
|
|
|
|
|
|
|
|
|
|
if (!candidates) {
|
|
|
|
|
throw new Error(`golang download url did not return results: ${dlUrl}`);
|
|
|
|
@ -81,7 +91,7 @@ export async function findMatch(versionSpec: string, stable: boolean): Promise<I
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (match && goFile) {
|
|
|
|
|
match.files = [goFile];
|
|
|
|
|