2019-09-21 03:41:21 +02:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as exec from '@actions/exec';
|
2020-01-17 20:36:10 +01:00
|
|
|
import {getLatestVersion} from './get-latest-version';
|
|
|
|
import {installer} from './installer';
|
2019-09-21 03:41:21 +02:00
|
|
|
|
2020-01-17 20:36:10 +01:00
|
|
|
export interface actionResult {
|
|
|
|
exitcode: number;
|
|
|
|
output: string;
|
|
|
|
}
|
2019-09-21 03:41:21 +02:00
|
|
|
|
2020-01-17 20:36:10 +01:00
|
|
|
export async function showVersion(
|
|
|
|
cmd: string,
|
|
|
|
args: string[]
|
|
|
|
): Promise<actionResult> {
|
2019-09-21 03:41:21 +02:00
|
|
|
try {
|
2020-01-17 20:36:10 +01:00
|
|
|
let result: actionResult = {
|
|
|
|
exitcode: 0,
|
|
|
|
output: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
listeners: {
|
|
|
|
stdout: (data: Buffer) => {
|
|
|
|
result.output += data.toString();
|
2019-09-21 03:41:21 +02:00
|
|
|
}
|
2020-01-17 20:36:10 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
result.exitcode = await exec.exec(cmd, args, options);
|
|
|
|
core.debug(`
|
|
|
|
exit code: ${result.exitcode}
|
|
|
|
stdout: ${result.output}
|
|
|
|
`);
|
|
|
|
return result;
|
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
try {
|
|
|
|
const toolVersion: string = core.getInput('hugo-version');
|
|
|
|
let installVersion: string = '';
|
|
|
|
|
|
|
|
let result: actionResult = {
|
|
|
|
exitcode: 0,
|
|
|
|
output: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
if (toolVersion === '' || toolVersion === 'latest') {
|
|
|
|
installVersion = await getLatestVersion('gohugoio', 'hugo', 'brew');
|
2019-09-21 03:41:21 +02:00
|
|
|
} else {
|
2020-01-17 20:36:10 +01:00
|
|
|
installVersion = toolVersion;
|
2019-09-21 03:41:21 +02:00
|
|
|
}
|
2020-01-17 20:36:10 +01:00
|
|
|
|
|
|
|
core.info(`hugo version: ${installVersion}`);
|
|
|
|
await installer(installVersion);
|
|
|
|
result = await showVersion('hugo', ['version']);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
} catch (e) {
|
|
|
|
core.setFailed(`Action failed with error ${e}`);
|
|
|
|
return e;
|
2019-09-21 03:41:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run();
|