mirror of
https://github.com/actions/setup-go.git
synced 2024-11-22 04:51:01 -05:00
format
This commit is contained in:
parent
4282769cc0
commit
dc575ee3b3
7 changed files with 108 additions and 91 deletions
|
@ -28,12 +28,15 @@ describe('setup-go', () => {
|
|||
cnSpy = jest.spyOn(process.stdout, 'write');
|
||||
platSpy = jest.spyOn(sys, 'getPlatform');
|
||||
archSpy = jest.spyOn(sys, 'getArch');
|
||||
dlSpy = jest.spyOn(tc, "downloadTool");
|
||||
exSpy = jest.spyOn(tc, "extractTar");
|
||||
dlSpy = jest.spyOn(tc, 'downloadTool');
|
||||
exSpy = jest.spyOn(tc, 'extractTar');
|
||||
getSpy = jest.spyOn(http, 'getJson');
|
||||
getSpy.mockImplementation(() => <ITypedResponse<im.IGoVersion[]>>{
|
||||
getSpy.mockImplementation(
|
||||
() =>
|
||||
<ITypedResponse<im.IGoVersion[]>>{
|
||||
result: goJsonData
|
||||
});
|
||||
}
|
||||
);
|
||||
cnSpy.mockImplementation(line => {
|
||||
// uncomment to debug
|
||||
//process.stderr.write('write2:' + line + '\n');
|
||||
|
@ -49,7 +52,7 @@ describe('setup-go', () => {
|
|||
afterAll(async () => {}, 100000);
|
||||
|
||||
it('finds a version of go already in the cache', async () => {
|
||||
inSpy.mockImplementation(() => '1.13.0')
|
||||
inSpy.mockImplementation(() => '1.13.0');
|
||||
let toolPath = path.normalize('/cache/go/1.13.0/x64');
|
||||
tcSpy.mockImplementation(() => toolPath);
|
||||
await run();
|
||||
|
@ -79,7 +82,9 @@ describe('setup-go', () => {
|
|||
});
|
||||
|
||||
it('can mock go versions query', async () => {
|
||||
let r: ITypedResponse<im.IGoVersion[]> = await http.getJson<im.IGoVersion[]>('https://asite.notexist.com/path');
|
||||
let r: ITypedResponse<im.IGoVersion[]> = await http.getJson<
|
||||
im.IGoVersion[]
|
||||
>('https://asite.notexist.com/path');
|
||||
expect(r).toBeDefined();
|
||||
let versions = r.result;
|
||||
expect(versions).toBeDefined();
|
||||
|
|
8
dist/index.js
vendored
8
dist/index.js
vendored
|
@ -1287,7 +1287,7 @@ function run() {
|
|||
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
||||
//
|
||||
let versionSpec = core.getInput('go-version');
|
||||
let stable = (core.getInput('stable') || '').toUpperCase() == "TRUE";
|
||||
let stable = (core.getInput('stable') || '').toUpperCase() == 'TRUE';
|
||||
if (versionSpec) {
|
||||
let installDir = tc.find('go', versionSpec);
|
||||
if (!installDir) {
|
||||
|
@ -4591,8 +4591,9 @@ function downloadGo(versionSpec, stable) {
|
|||
let downloadUrl = `https://storage.googleapis.com/golang/${match.files[0]}`;
|
||||
let downloadPath = yield tc.downloadTool(downloadUrl);
|
||||
// extract
|
||||
let extPath = sys.getPlatform() == 'windows' ?
|
||||
yield tc.extractZip(downloadPath) : yield tc.extractTar(downloadPath);
|
||||
let extPath = sys.getPlatform() == 'windows'
|
||||
? yield tc.extractZip(downloadPath)
|
||||
: yield tc.extractTar(downloadPath);
|
||||
// extracts with a root folder that matches the fileName downloaded
|
||||
const toolRoot = path.join(extPath, 'go');
|
||||
toolPath = yield tc.cacheDir(toolRoot, 'go', versionSpec);
|
||||
|
@ -4638,7 +4639,6 @@ function findMatch(versionSpec, stable) {
|
|||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
if (match && goFile) {
|
||||
match.files = [goFile];
|
||||
}
|
||||
|
|
|
@ -30,8 +30,9 @@ function downloadGo(versionSpec, stable) {
|
|||
let downloadUrl = `https://storage.googleapis.com/golang/${match.files[0]}`;
|
||||
let downloadPath = yield tc.downloadTool(downloadUrl);
|
||||
// extract
|
||||
let extPath = sys.getPlatform() == 'windows' ?
|
||||
yield tc.extractZip(downloadPath) : yield tc.extractTar(downloadPath);
|
||||
let extPath = sys.getPlatform() == 'windows'
|
||||
? yield tc.extractZip(downloadPath)
|
||||
: yield tc.extractTar(downloadPath);
|
||||
// extracts with a root folder that matches the fileName downloaded
|
||||
const toolRoot = path.join(extPath, 'go');
|
||||
toolPath = yield tc.cacheDir(toolRoot, 'go', versionSpec);
|
||||
|
@ -77,7 +78,6 @@ function findMatch(versionSpec, stable) {
|
|||
}
|
||||
}
|
||||
}
|
||||
;
|
||||
if (match && goFile) {
|
||||
match.files = [goFile];
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
|
|
10
src/main.ts
10
src/main.ts
|
@ -10,7 +10,8 @@ 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);
|
||||
|
@ -22,9 +23,10 @@ export async function run() {
|
|||
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}`);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Could not find a version that satisfied version spec: ${versionSpec}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
import {run} from './main'
|
||||
import {run} from './main';
|
||||
|
||||
run();
|
||||
|
|
Loading…
Reference in a new issue