mirror of
https://github.com/peaceiris/actions-hugo.git
synced 2026-01-25 12:22:17 +01:00
test: Add integration testing (#131)
* docs: Update description * deps: Add nock * chore: Add resolveJsonModule * test: Add integration testing * chore: Add @typescript-eslint/eslint-plugin * refactor: Fix lint errors * chore: Add eslint-plugin-jest * refactor: Fix lint errors * test: Add remove working files * ci: Comment out cache steps
This commit is contained in:
65
src/main.ts
Normal file
65
src/main.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
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 {
|
||||
exitcode: number;
|
||||
output: string;
|
||||
}
|
||||
|
||||
export async function showVersion(
|
||||
cmd: string,
|
||||
args: string[]
|
||||
): Promise<ActionResult> {
|
||||
const result: ActionResult = {
|
||||
exitcode: 0,
|
||||
output: ''
|
||||
};
|
||||
|
||||
const options = {
|
||||
listeners: {
|
||||
stdout: (data: Buffer): void => {
|
||||
result.output += data.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
result.exitcode = await exec.exec(cmd, args, options);
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
core.debug(`command: ${cmd} ${args}`);
|
||||
core.debug(`exit code: ${result.exitcode}`);
|
||||
core.debug(`stdout: ${result.output}`);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function run(): Promise<ActionResult> {
|
||||
try {
|
||||
const toolVersion: string = core.getInput('hugo-version');
|
||||
let installVersion = '';
|
||||
|
||||
let result: ActionResult = {
|
||||
exitcode: 0,
|
||||
output: ''
|
||||
};
|
||||
|
||||
if (toolVersion === '' || toolVersion === 'latest') {
|
||||
installVersion = await getLatestVersion(Tool.Org, Tool.Repo, 'brew');
|
||||
} else {
|
||||
installVersion = toolVersion;
|
||||
}
|
||||
|
||||
core.info(`${Tool.Name} version: ${installVersion}`);
|
||||
await installer(installVersion);
|
||||
result = await showVersion(Tool.CmdName, [Tool.CmdOptVersion]);
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
core.setFailed(`Action failed with error ${e}`);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user