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