d46d0aa12e
Refactoring * feat: Add reject to Promise * feat: Add printing inputs * feat: Add error handling to getLatestVersion() * feat: show version of Hugo, Go, and Git (Close #23) * refactor: Get the latest version from Homebrew (Close #26) * refactor: enhance error message of promise reject Enhancement for workflow * gha: Add deps (test-prod job needs test job) * gha: Fix matrix testing * gha: comment out Build production step * gha: remove Dump step Update README * docs: update readme
57 lines
1.8 KiB
JavaScript
57 lines
1.8 KiB
JavaScript
const core = require("@actions/core");
|
|
const tc = require("@actions/tool-cache");
|
|
const io = require("@actions/io");
|
|
const exec = require("@actions/exec");
|
|
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;
|
|
}
|
|
console.log(`Hugo version: ${hugoVersion}`);
|
|
|
|
const 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);
|
|
|
|
// Show version
|
|
await exec.exec('hugo version');
|
|
await exec.exec('go version');
|
|
await exec.exec('git --version');
|
|
},
|
|
function(error) {
|
|
core.setFailed(error);
|
|
}
|
|
);
|
|
} catch (error) {
|
|
core.setFailed(error.message);
|
|
}
|
|
}
|
|
|
|
run();
|