refactor: Fix lint errors
This commit is contained in:
parent
e844f436b5
commit
950c4d588e
7 changed files with 31 additions and 25 deletions
|
|
@ -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: ''
|
||||
};
|
||||
|
|
|
|||
7
src/constants.ts
Normal file
7
src/constants.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
export enum Tool {
|
||||
Name = 'Hugo',
|
||||
Org = 'gohugoio',
|
||||
Repo = 'hugo',
|
||||
CmdName = 'hugo',
|
||||
CmdOptVersion = 'version'
|
||||
}
|
||||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ if (!tempDir) {
|
|||
tempDir = path.join(baseTempLocation, 'tmp');
|
||||
}
|
||||
|
||||
export async function installer(version: string) {
|
||||
export async function installer(version: string): Promise<void> {
|
||||
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,
|
||||
|
|
|
|||
21
src/main.ts
21
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<actionResult> {
|
||||
): Promise<ActionResult> {
|
||||
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<ActionResult> {
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue