From dc575ee3b360272cba6a31bba31768520c92552b Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Sun, 9 Feb 2020 00:29:21 -0500 Subject: [PATCH] format --- __tests__/setup-go.test.ts | 45 ++++++++++++++------------ dist/index.js | 8 ++--- lib/installer.js | 6 ++-- src/installer.ts | 42 +++++++++++++++--------- src/main.ts | 30 +++++++++-------- src/setup-go.ts | 2 +- src/system.ts | 66 +++++++++++++++++++------------------- 7 files changed, 108 insertions(+), 91 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 622fdfa..2f8bd53 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -7,7 +7,7 @@ import {run} from '../src/main'; import * as httpm from '@actions/http-client'; import * as im from '../src/installer'; import * as sys from '../src/system'; -import { ITypedResponse } from '@actions/http-client/interfaces'; +import {ITypedResponse} from '@actions/http-client/interfaces'; let goJsonData = require('./data/golang-dl.json'); @@ -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(() => >{ - result: goJsonData - }); + getSpy.mockImplementation( + () => + >{ + 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,14 +82,16 @@ describe('setup-go', () => { }); it('can mock go versions query', async () => { - let r: ITypedResponse = await http.getJson('https://asite.notexist.com/path'); + let r: ITypedResponse = await http.getJson< + im.IGoVersion[] + >('https://asite.notexist.com/path'); expect(r).toBeDefined(); let versions = r.result; expect(versions).toBeDefined(); - let l:number = versions? versions.length: 0; + let l: number = versions ? versions.length : 0; expect(l).toBe(76); }); - + it('finds stable match for exact version', async () => { platSpy.mockImplementation(() => 'linux'); archSpy.mockImplementation(() => 'amd64'); @@ -97,10 +102,10 @@ describe('setup-go', () => { expect(match).toBeDefined(); let version: string = match ? match.version : ''; expect(version).toBe('go1.13.1'); - let fileName = match ? match.files[0].filename: ''; + let fileName = match ? match.files[0].filename : ''; expect(fileName).toBe('go1.13.1.linux-amd64.tar.gz'); }); - + it('finds stable match for exact dot zero version', async () => { platSpy.mockImplementation(() => 'linux'); archSpy.mockImplementation(() => 'amd64'); @@ -110,10 +115,10 @@ describe('setup-go', () => { expect(match).toBeDefined(); let version: string = match ? match.version : ''; expect(version).toBe('go1.13'); - let fileName = match ? match.files[0].filename: ''; + let fileName = match ? match.files[0].filename : ''; expect(fileName).toBe('go1.13.linux-amd64.tar.gz'); }); - + it('finds latest patch version for minor version spec', async () => { platSpy.mockImplementation(() => 'linux'); archSpy.mockImplementation(() => 'amd64'); @@ -123,10 +128,10 @@ describe('setup-go', () => { expect(match).toBeDefined(); let version: string = match ? match.version : ''; expect(version).toBe('go1.13.7'); - let fileName = match ? match.files[0].filename: ''; + let fileName = match ? match.files[0].filename : ''; expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz'); }); - + it('finds latest patch version for caret version spec', async () => { platSpy.mockImplementation(() => 'linux'); archSpy.mockImplementation(() => 'amd64'); @@ -136,10 +141,10 @@ describe('setup-go', () => { expect(match).toBeDefined(); let version: string = match ? match.version : ''; expect(version).toBe('go1.13.7'); - let fileName = match ? match.files[0].filename: ''; + let fileName = match ? match.files[0].filename : ''; expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz'); }); - + it('finds latest version for major version spec', async () => { platSpy.mockImplementation(() => 'linux'); archSpy.mockImplementation(() => 'amd64'); @@ -149,7 +154,7 @@ describe('setup-go', () => { expect(match).toBeDefined(); let version: string = match ? match.version : ''; expect(version).toBe('go1.13.7'); - let fileName = match ? match.files[0].filename: ''; + let fileName = match ? match.files[0].filename : ''; expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz'); - }); + }); }); diff --git a/dist/index.js b/dist/index.js index cd79128..abf8c8e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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]; } diff --git a/lib/installer.js b/lib/installer.js index 1b4ee16..04efe48 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -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]; } diff --git a/src/installer.ts b/src/installer.ts index f925b46..a719df7 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -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 { +export async function downloadGo( + versionSpec: string, + stable: boolean +): Promise { 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 { +export async function findMatch( + versionSpec: string, + stable: boolean +): Promise { 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(dlUrl)).result; + let candidates: IGoVersion[] | null = (await http.getJson( + 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