refactor: enhance error handling

This commit is contained in:
peaceiris 2019-09-21 09:46:58 +09:00
parent 2eb9c97d23
commit f9f7965bdf
2 changed files with 45 additions and 68 deletions

View file

@ -5,30 +5,31 @@ import installer from "./installer";
// most @actions toolkit packages have async methods
async function run() {
const dump = async () => {
// Show version
await exec.exec("hugo version");
await exec.exec("go version");
await exec.exec("git --version");
};
try {
getLatestVersion().then(
async function(latestVersion): Promise<void> {
const hugoVersion: string = core.getInput("hugo-version");
console.log(`Hugo version: ${hugoVersion}`);
const version = (v: string, latestVersion: string): string => {
if (v === "" || v === "latest") {
return latestVersion;
} else {
return v;
}
};
const hugoVersion: string = core.getInput("hugo-version");
console.log(`Hugo version: ${hugoVersion}`);
await installer(version(hugoVersion, latestVersion));
// Show version
await exec.exec("hugo version");
await exec.exec("go version");
await exec.exec("git --version");
},
function(error) {
core.setFailed(error);
}
);
if (hugoVersion === "" || hugoVersion === "latest") {
getLatestVersion().then(
async function(latestVersion): Promise<void> {
await installer(latestVersion);
await dump();
},
function(error) {
core.setFailed(error);
}
);
} else {
await installer(hugoVersion);
await dump();
}
} catch (error) {
core.setFailed(error.message);
}