feat: Add error handling to getLatestVersion()

This commit is contained in:
peaceiris 2019-09-18 02:27:59 +09:00
parent 2d7a42afa8
commit bc7b30b91d

View file

@ -6,46 +6,44 @@ const getLatestVersion = require("./get-latest-version");
// most @actions toolkit packages have async methods // most @actions toolkit packages have async methods
async function run() { async function run() {
try { try {
getLatestVersion().then(async function(latestVersion) { getLatestVersion().then(
let hugoVersion = core.getInput("hugo-version"); async function(latestVersion) {
if (!hugoVersion || hugoVersion === "latest") { let hugoVersion = core.getInput("hugo-version");
hugoVersion = latestVersion; if (!hugoVersion || hugoVersion === "latest") {
hugoVersion = latestVersion;
}
console.log(`Hugo version: ${hugoVersion}`);
let extended = core.getInput("extended");
console.log(`Hugo extended: ${extended}`);
let extendedStr = "";
if (extended === "true") {
extendedStr = "extended_";
}
console.log(`Operating System: ${process.platform}`);
const hugoName = `hugo_${extendedStr}${hugoVersion}_Linux-64bit`;
core.debug(`hugoName: ${hugoName}`);
const hugoURL = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/${hugoName}.tar.gz`;
core.debug(`hugoURL: ${hugoURL}`);
const hugoPath = `${process.env.HOME}/bin`;
await io.mkdirP(hugoPath);
core.addPath(hugoPath);
// Download and extract Hugo binary
const hugoTarball = await tc.downloadTool(hugoURL);
const hugoExtractedFolder = await tc.extractTar(hugoTarball, "/tmp");
core.debug("hugoExtractedFolder:", hugoExtractedFolder);
await io.mv(`${hugoExtractedFolder}/hugo`, hugoPath);
},
function(error) {
console.error(error);
} }
console.log(`Hugo version: ${hugoVersion}`); );
let extended = core.getInput("extended");
console.log(`Hugo extended: ${extended}`);
let extendedStr = "";
if (extended === "true") {
extendedStr = "extended_";
}
console.log(`Operating System: ${process.platform}`);
const hugoName = `hugo_${extendedStr}${hugoVersion}_Linux-64bit`;
core.debug(`hugoName: ${hugoName}`);
const hugoURL = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/${hugoName}.tar.gz`;
core.debug(`hugoURL: ${hugoURL}`);
const hugoPath = `${process.env.HOME}/bin`;
await io.mkdirP(hugoPath);
core.addPath(hugoPath);
// Download and extract Hugo binary
const hugoTarball = await tc.downloadTool(hugoURL);
const hugoExtractedFolder = await tc.extractTar(hugoTarball, "/tmp");
core.debug("hugoExtractedFolder:", hugoExtractedFolder);
await io.mv(`${hugoExtractedFolder}/hugo`, hugoPath);
// },
// function(error) {
// console.error(error);
// console.log(
// "HINT: GitHub API Rate limiting",
// "https://developer.github.com/v3/#rate-limiting"
// );
});
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }