actions-hugo/index.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

const core = require('@actions/core');
2019-09-15 18:32:20 +02:00
const exec = require('@actions/exec');
const tc = require('@actions/tool-cache');
const io = require('@actions/io');
2019-09-15 17:22:08 +02:00
// const wait = require('./wait');
// most @actions toolkit packages have async methods
async function run() {
2019-09-15 13:24:31 +02:00
try {
2019-09-15 17:04:26 +02:00
// const ms = core.getInput('milliseconds');
// console.log(`Waiting ${ms} milliseconds ...`)
2019-09-15 17:04:26 +02:00
// core.debug((new Date()).toTimeString())
// wait(parseInt(ms));
// core.debug((new Date()).toTimeString())
2019-09-15 17:04:26 +02:00
// core.setOutput('time', new Date().toTimeString());
2019-09-15 13:24:31 +02:00
2019-09-15 18:32:20 +02:00
let hugoVersion = core.getInput('hugo-version');
2019-09-15 17:22:08 +02:00
if (!hugoVersion) {
hugoVersion = 'latest';
}
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);
const hugoTarball = await tc.downloadTool(hugoURL);
const hugoExtractedFolder = await tc.extractTar(hugoTarball, '/tmp/hugo');
core.debug('hugoExtractedFolder:', hugoExtractedFolder);
await io.mv('/tmp/hugo/hugo', '/usr/local/bin/');
2019-09-15 13:24:31 +02:00
}
catch (error) {
core.setFailed(error.message);
}
}
run()