actions-hugo/index.js

46 lines
1.4 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");
2019-09-15 20:16:06 +02:00
const getLatestVersion = require("./get-latest-version");
// most @actions toolkit packages have async methods
async function run() {
2019-09-15 13:24:31 +02:00
try {
2019-09-15 21:53:14 +02:00
getLatestVersion().then(async function(latestVersion) {
2019-09-15 21:49:06 +02:00
let hugoVersion = core.getInput("hugo-version");
if (!hugoVersion || hugoVersion === "latest") {
hugoVersion = latestVersion;
}
core.debug(`Hugo version: ${hugoVersion}`);
let extended = core.getInput("extended");
core.debug(`Hugo extended: ${extended}`);
let extendedStr = "";
if (extended) {
extendedStr = "extended_";
}
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}`);
2019-09-15 22:22:01 +02:00
const hugoPath = "/home/runner/bin";
2019-09-15 21:49:06 +02:00
await io.mkdirP(hugoPath);
2019-09-15 22:22:01 +02:00
core.addPath(hugoPath);
2019-09-15 21:49:06 +02:00
// Download and extract Hugo binary
const hugoTarball = await tc.downloadTool(hugoURL);
const hugoExtractedFolder = await tc.extractTar(hugoTarball, "/tmp");
core.debug("hugoExtractedFolder:", hugoExtractedFolder);
2019-09-15 22:22:01 +02:00
await io.mv(`${hugoExtractedFolder}/hugo`, hugoPath);
2019-09-15 21:49:06 +02:00
});
2019-09-15 19:31:49 +02:00
} catch (error) {
core.setFailed(error.message);
}
}
2019-09-15 19:31:49 +02:00
run();