actions-hugo/index.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-09-15 19:31:49 +02:00
const core = require("@actions/core");
const tc = require("@actions/tool-cache");
const io = require("@actions/io");
const exec = require("@actions/exec");
// most @actions toolkit packages have async methods
async function run() {
2019-09-15 13:24:31 +02:00
try {
2019-09-15 19:31:49 +02:00
let hugoVersion = core.getInput("hugo-version");
2019-09-15 17:22:08 +02:00
if (!hugoVersion) {
2019-09-15 19:34:54 +02:00
// TODO: get latest version of Hugo
// hugoVersion = "latest";
hugoVersion = "0.58.2";
2019-09-15 19:31:49 +02:00
} else if (hugoVersion === "latest") {
2019-09-15 18:49:48 +02:00
// TODO: get latest version of Hugo
2019-09-15 19:31:49 +02:00
hugoVersion = "0.58.2";
2019-09-15 17:22:08 +02:00
}
2019-09-15 19:31:49 +02:00
core.debug("Hugo version:", hugoVersion);
2019-09-15 13:24:31 +02:00
2019-09-15 19:31:49 +02:00
let extended = core.getInput("extended");
2019-09-15 17:26:11 +02:00
if (!extended) {
extended = false;
}
2019-09-15 19:31:49 +02:00
core.debug("Hugo extended:", extended);
2019-09-15 18:32:20 +02:00
2019-09-15 19:31:49 +02:00
let extendedStr = "";
2019-09-15 18:32:20 +02:00
if (extended) {
2019-09-15 19:31:49 +02:00
extendedStr = "extended_";
2019-09-15 18:32:20 +02:00
}
const hugoName = `hugo_${extendedStr}${hugoVersion}_Linux-64bit`;
2019-09-15 19:31:49 +02:00
core.debug("hugoName:", hugoName);
2019-09-15 18:32:20 +02:00
const hugoURL = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/${hugoName}.tar.gz`;
2019-09-15 19:31:49 +02:00
core.debug("hugoURL:", hugoURL);
2019-09-15 18:32:20 +02:00
2019-09-15 19:31:49 +02:00
const hugoPath = "/usr/local/bin";
2019-09-15 19:03:41 +02:00
await io.mkdirP(hugoPath);
2019-09-15 19:06:57 +02:00
// Download and extract Hugo binary
2019-09-15 18:32:20 +02:00
const hugoTarball = await tc.downloadTool(hugoURL);
2019-09-15 19:31:49 +02:00
const hugoExtractedFolder = await tc.extractTar(hugoTarball, "/tmp");
core.debug("hugoExtractedFolder:", hugoExtractedFolder);
await exec.exec("sudo", ["mv", `${hugoExtractedFolder}/hugo`, hugoPath]);
} catch (error) {
core.setFailed(error.message);
}
}
2019-09-15 19:31:49 +02:00
run();