diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 2593eff..9ac851a 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -20,7 +20,7 @@ describe('Integration testing run()', () => { test('succeed in installing a custom version', async () => { const testVersion: string = '0.61.0'; process.env['INPUT_HUGO-VERSION'] = testVersion; - const result: main.actionResult = await main.run(); + const result: main.ActionResult = await main.run(); expect(result.exitcode).toBe(0); expect(result.output).toMatch(`Hugo Static Site Generator v${testVersion}`); }); @@ -31,14 +31,14 @@ describe('Integration testing run()', () => { nock('https://formulae.brew.sh') .get(`/api/formula/${repo}.json`) .reply(200, jsonTestBrew); - const result: main.actionResult = await main.run(); + const result: main.ActionResult = await main.run(); expect(result.exitcode).toBe(0); expect(result.output).toMatch('Hugo Static Site Generator v0.62.2'); }); }); describe('showVersion()', () => { - let result: main.actionResult = { + let result: main.ActionResult = { exitcode: 0, output: '' }; diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..e305ca4 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,7 @@ +export enum Tool { + Name = 'Hugo', + Org = 'gohugoio', + Repo = 'hugo', + CmdName = 'hugo', + CmdOptVersion = 'version' +} diff --git a/src/get-latest-version.ts b/src/get-latest-version.ts index f0031a3..e6f3c37 100644 --- a/src/get-latest-version.ts +++ b/src/get-latest-version.ts @@ -1,7 +1,7 @@ import fetch from 'node-fetch'; export function getURL(org: string, repo: string, api: string): string { - let url: string = ''; + let url = ''; if (api === 'brew') { url = `https://formulae.brew.sh/api/formula/${repo}.json`; @@ -21,7 +21,7 @@ export async function getLatestVersion( const url = getURL(org, repo, api); const response = await fetch(url); const json = await response.json(); - let latestVersion: string = ''; + let latestVersion = ''; if (api === 'brew') { latestVersion = json.versions.stable; } else if (api === 'github') { diff --git a/src/get-os.ts b/src/get-os.ts index b94917a..38a2eba 100644 --- a/src/get-os.ts +++ b/src/get-os.ts @@ -1,4 +1,4 @@ -export default function getOS(platform: string) { +export default function getOS(platform: string): string { if (platform === 'linux') { return 'Linux'; } else if (platform === 'darwin') { diff --git a/src/get-url.ts b/src/get-url.ts index 42bd9af..ea9726c 100644 --- a/src/get-url.ts +++ b/src/get-url.ts @@ -3,7 +3,7 @@ export default function getURL( extended: string, version: string ): string { - const extendedStr = (extended: string) => { + const extendedStr = (extended: string): string => { if (extended === 'true') { return 'extended_'; } else { @@ -13,7 +13,7 @@ export default function getURL( } }; - const ext = (os: string) => { + const ext = (os: string): string => { if (os === 'Windows') { return 'zip'; } else { @@ -21,11 +21,9 @@ export default function getURL( } }; - const hugoName: string = `hugo_${extendedStr( - extended - )}${version}_${os}-64bit`; - const baseURL: string = 'https://github.com/gohugoio/hugo/releases/download'; - const url: string = `${baseURL}/v${version}/${hugoName}.${ext(os)}`; + const hugoName = `hugo_${extendedStr(extended)}${version}_${os}-64bit`; + const baseURL = 'https://github.com/gohugoio/hugo/releases/download'; + const url = `${baseURL}/v${version}/${hugoName}.${ext(os)}`; return url; } diff --git a/src/installer.ts b/src/installer.ts index 5ce0f37..fb9179e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -16,7 +16,7 @@ if (!tempDir) { tempDir = path.join(baseTempLocation, 'tmp'); } -export async function installer(version: string) { +export async function installer(version: string): Promise { try { const extended: string = core.getInput('extended'); console.log(`Hugo extended: ${extended}`); @@ -40,7 +40,7 @@ export async function installer(version: string) { // Download and extract Hugo binary await io.mkdirP(tempDir); const hugoAssets: string = await tc.downloadTool(hugoURL); - let hugoBin: string = ''; + let hugoBin = ''; if (osName === 'Windows') { const hugoExtractedFolder: string = await tc.extractZip( hugoAssets, diff --git a/src/main.ts b/src/main.ts index 7ebfc21..13b31de 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,8 +2,9 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import {getLatestVersion} from './get-latest-version'; import {installer} from './installer'; +import {Tool} from './constants'; -export interface actionResult { +export interface ActionResult { exitcode: number; output: string; } @@ -11,16 +12,16 @@ export interface actionResult { export async function showVersion( cmd: string, args: string[] -): Promise { +): Promise { try { - let result: actionResult = { + const result: ActionResult = { exitcode: 0, output: '' }; const options = { listeners: { - stdout: (data: Buffer) => { + stdout: (data: Buffer): void => { result.output += data.toString(); } } @@ -37,25 +38,25 @@ export async function showVersion( } } -export async function run() { +export async function run(): Promise { try { const toolVersion: string = core.getInput('hugo-version'); - let installVersion: string = ''; + let installVersion = ''; - let result: actionResult = { + let result: ActionResult = { exitcode: 0, output: '' }; if (toolVersion === '' || toolVersion === 'latest') { - installVersion = await getLatestVersion('gohugoio', 'hugo', 'brew'); + installVersion = await getLatestVersion(Tool.Org, Tool.Repo, 'brew'); } else { installVersion = toolVersion; } - core.info(`hugo version: ${installVersion}`); + core.info(`${Tool.Name} version: ${installVersion}`); await installer(installVersion); - result = await showVersion('hugo', ['version']); + result = await showVersion(Tool.CmdName, [Tool.CmdOptVersion]); return result; } catch (e) {