From bc7b30b91d1295893efe03fff0b0906e301a5ef2 Mon Sep 17 00:00:00 2001 From: peaceiris <30958501+peaceiris@users.noreply.github.com> Date: Wed, 18 Sep 2019 02:27:59 +0900 Subject: [PATCH] feat: Add error handling to getLatestVersion() --- index.js | 76 +++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/index.js b/index.js index b68c061..890028d 100644 --- a/index.js +++ b/index.js @@ -6,46 +6,44 @@ const getLatestVersion = require("./get-latest-version"); // most @actions toolkit packages have async methods async function run() { try { - getLatestVersion().then(async function(latestVersion) { - let hugoVersion = core.getInput("hugo-version"); - if (!hugoVersion || hugoVersion === "latest") { - hugoVersion = latestVersion; + getLatestVersion().then( + async function(latestVersion) { + let hugoVersion = core.getInput("hugo-version"); + 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) { core.setFailed(error.message); }