actions-hugo/index.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

const core = require('@actions/core');
2019-09-15 18:32:20 +02:00
const tc = require('@actions/tool-cache');
const io = require('@actions/io');
// most @actions toolkit packages have async methods
async function run() {
2019-09-15 13:24:31 +02:00
try {
2019-09-15 18:32:20 +02:00
let hugoVersion = core.getInput('hugo-version');
2019-09-15 17:22:08 +02:00
if (!hugoVersion) {
2019-09-15 18:49:48 +02:00
// TODO: get latest version of Hugo
hugoVersion = '0.58.2';
2019-09-15 17:22:08 +02:00
}
2019-09-15 18:32:20 +02:00
core.debug('Hugo version:', hugoVersion);
2019-09-15 13:24:31 +02:00
2019-09-15 18:32:20 +02:00
let extended = core.getInput('extended');
2019-09-15 17:26:11 +02:00
if (!extended) {
extended = false;
}
2019-09-15 18:32:20 +02:00
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 19:03:41 +02:00
const hugoPath = '/github/home/bin';
await io.mkdirP(hugoPath);
2019-09-15 19:06:57 +02:00
core.addPath(hugoPath);
// Download and extract Hugo binary
2019-09-15 18:32:20 +02:00
const hugoTarball = await tc.downloadTool(hugoURL);
2019-09-15 18:53:34 +02:00
const hugoExtractedFolder = await tc.extractTar(hugoTarball, '/tmp');
2019-09-15 18:32:20 +02:00
core.debug('hugoExtractedFolder:', hugoExtractedFolder);
2019-09-15 19:03:41 +02:00
await io.mv(`${hugoExtractedFolder}/hugo`, hugoPath);
2019-09-15 13:24:31 +02:00
}
catch (error) {
core.setFailed(error.message);
}
}
run()