actions-hugo/lib/index.js

54 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-09-16 08:27:57 +09:00
const core = require("@actions/core");
const tc = require("@actions/tool-cache");
const io = require("@actions/io");
const exec = require("@actions/exec");
2019-09-18 09:59:07 +09:00
const getOS = require("./get-os");
2019-09-20 06:54:14 +09:00
const getURL = require("./get-url");
2019-09-16 08:27:57 +09:00
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}`);
2019-09-18 09:59:07 +09:00
const osName = getOS(process.platform);
console.log(`Operating System: ${osName}`);
2019-09-20 06:54:14 +09:00
const hugoURL = getURL(osName, extended, hugoVersion);
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
2019-09-19 17:34:59 +09:00
await exec.exec("hugo version");
await exec.exec("go version");
await exec.exec("git --version");
},
function(error) {
core.setFailed(error);
2019-09-16 08:27:57 +09:00
}
);
2019-09-16 08:27:57 +09:00
} catch (error) {
core.setFailed(error.message);
}
}
run();