mirror of
https://github.com/actions/setup-go.git
synced 2025-06-24 05:47:57 +02:00
format
This commit is contained in:
@ -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,26 +48,31 @@ 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();
|
||||
|
||||
let match: IGoVersion| undefined;
|
||||
let match: IGoVersion | undefined;
|
||||
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
||||
|
||||
// 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}`);
|
||||
}
|
||||
|
||||
|
||||
let goFile: IGoVersionFile | undefined;
|
||||
for (let i=0; i < candidates.length; i++) {
|
||||
for (let i = 0; i < candidates.length; i++) {
|
||||
let candidate: IGoVersion = candidates[i];
|
||||
let version = candidate.version.replace('go', '');
|
||||
|
||||
|
||||
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
|
||||
// since a semver of 1.13 would match latest 1.13
|
||||
let parts: string[] = version.split('.');
|
||||
@ -81,10 +91,10 @@ export async function findMatch(versionSpec: string, stable: boolean): Promise<I
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (match && goFile) {
|
||||
match.files = [ goFile ];
|
||||
match.files = [goFile];
|
||||
}
|
||||
|
||||
return match;
|
||||
|
30
src/main.ts
30
src/main.ts
@ -10,22 +10,24 @@ export async function run() {
|
||||
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
||||
//
|
||||
let versionSpec = core.getInput('go-version');
|
||||
let stable: boolean = (core.getInput('stable') || '').toUpperCase() == "TRUE";
|
||||
let stable: boolean =
|
||||
(core.getInput('stable') || '').toUpperCase() == 'TRUE';
|
||||
|
||||
if (versionSpec) {
|
||||
let installDir: string | undefined = tc.find('go', versionSpec);
|
||||
let installDir: string | undefined = tc.find('go', versionSpec);
|
||||
|
||||
if (!installDir) {
|
||||
installDir = await installer.downloadGo(versionSpec, stable);
|
||||
}
|
||||
|
||||
if (installDir) {
|
||||
core.exportVariable('GOROOT', installDir);
|
||||
core.addPath(path.join(installDir, 'bin'));
|
||||
}
|
||||
else {
|
||||
throw new Error(`Could not find a version that satisfied version spec: ${versionSpec}`);
|
||||
}
|
||||
if (!installDir) {
|
||||
installDir = await installer.downloadGo(versionSpec, stable);
|
||||
}
|
||||
|
||||
if (installDir) {
|
||||
core.exportVariable('GOROOT', installDir);
|
||||
core.addPath(path.join(installDir, 'bin'));
|
||||
} else {
|
||||
throw new Error(
|
||||
`Could not find a version that satisfied version spec: ${versionSpec}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// add problem matchers
|
||||
@ -34,4 +36,4 @@ export async function run() {
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
import {run} from './main'
|
||||
import {run} from './main';
|
||||
|
||||
run();
|
||||
|
@ -1,37 +1,37 @@
|
||||
import * as os from 'os';
|
||||
|
||||
export function getPlatform(): string {
|
||||
// darwin and linux match already
|
||||
// freebsd not supported yet but future proofed.
|
||||
|
||||
// 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32'
|
||||
let plat: string = os.platform();
|
||||
|
||||
// wants 'darwin', 'freebsd', 'linux', 'windows'
|
||||
if (plat === 'win32') {
|
||||
plat = 'windows';
|
||||
}
|
||||
|
||||
return plat;
|
||||
// darwin and linux match already
|
||||
// freebsd not supported yet but future proofed.
|
||||
|
||||
// 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32'
|
||||
let plat: string = os.platform();
|
||||
|
||||
// wants 'darwin', 'freebsd', 'linux', 'windows'
|
||||
if (plat === 'win32') {
|
||||
plat = 'windows';
|
||||
}
|
||||
|
||||
export function getArch(): string {
|
||||
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'.
|
||||
let arch: string = os.arch();
|
||||
|
||||
// wants amd64, 386, arm64, armv61, ppc641e, s390x
|
||||
// currently not supported by runner but future proofed mapping
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
arch = 'amd64';
|
||||
break;
|
||||
case 'ppc':
|
||||
arch = 'ppc64';
|
||||
break;
|
||||
case 'x32':
|
||||
arch = '386';
|
||||
break;
|
||||
}
|
||||
|
||||
return arch;
|
||||
}
|
||||
|
||||
return plat;
|
||||
}
|
||||
|
||||
export function getArch(): string {
|
||||
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'.
|
||||
let arch: string = os.arch();
|
||||
|
||||
// wants amd64, 386, arm64, armv61, ppc641e, s390x
|
||||
// currently not supported by runner but future proofed mapping
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
arch = 'amd64';
|
||||
break;
|
||||
case 'ppc':
|
||||
arch = 'ppc64';
|
||||
break;
|
||||
case 'x32':
|
||||
arch = '386';
|
||||
break;
|
||||
}
|
||||
|
||||
return arch;
|
||||
}
|
||||
|
Reference in New Issue
Block a user