2019-09-21 01:41:21 +00:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import * as tc from '@actions/tool-cache';
|
|
|
|
import * as io from '@actions/io';
|
|
|
|
import getOS from './get-os';
|
|
|
|
import getURL from './get-url';
|
2019-11-22 02:14:44 +00:00
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
let tempDir: string = process.env['RUNNER_TEMPDIRECTORY'] || '';
|
|
|
|
if (!tempDir) {
|
|
|
|
let baseTempLocation: string;
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
baseTempLocation = process.env['USERPROFILE'] || 'C:\\';
|
|
|
|
} else {
|
|
|
|
baseTempLocation = `${process.env.HOME}`;
|
|
|
|
}
|
|
|
|
tempDir = path.join(baseTempLocation, 'tmp');
|
|
|
|
}
|
2019-09-21 01:41:21 +00:00
|
|
|
|
2020-01-17 19:36:10 +00:00
|
|
|
export async function installer(version: string) {
|
2019-09-21 01:41:21 +00:00
|
|
|
try {
|
|
|
|
const extended: string = core.getInput('extended');
|
|
|
|
console.log(`Hugo extended: ${extended}`);
|
|
|
|
|
|
|
|
const osName: string = getOS(process.platform);
|
|
|
|
console.log(`Operating System: ${osName}`);
|
|
|
|
|
|
|
|
const hugoURL: string = getURL(osName, extended, version);
|
|
|
|
core.debug(`hugoURL: ${hugoURL}`);
|
|
|
|
|
2019-11-22 02:14:44 +00:00
|
|
|
let baseLocation: string;
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
baseLocation = process.env['USERPROFILE'] || 'C:\\';
|
|
|
|
} else {
|
|
|
|
baseLocation = `${process.env.HOME}`;
|
|
|
|
}
|
|
|
|
const hugoPath: string = path.join(baseLocation, 'hugobin');
|
2019-09-21 01:41:21 +00:00
|
|
|
await io.mkdirP(hugoPath);
|
|
|
|
core.addPath(hugoPath);
|
|
|
|
|
|
|
|
// Download and extract Hugo binary
|
2019-11-22 02:14:44 +00:00
|
|
|
await io.mkdirP(tempDir);
|
2019-09-21 01:41:21 +00:00
|
|
|
const hugoAssets: string = await tc.downloadTool(hugoURL);
|
|
|
|
let hugoBin: string = '';
|
|
|
|
if (osName === 'Windows') {
|
|
|
|
const hugoExtractedFolder: string = await tc.extractZip(
|
|
|
|
hugoAssets,
|
2019-11-22 02:14:44 +00:00
|
|
|
tempDir
|
2019-09-21 01:41:21 +00:00
|
|
|
);
|
|
|
|
hugoBin = `${hugoExtractedFolder}/hugo.exe`;
|
|
|
|
} else {
|
|
|
|
const hugoExtractedFolder: string = await tc.extractTar(
|
|
|
|
hugoAssets,
|
2019-11-22 02:14:44 +00:00
|
|
|
tempDir
|
2019-09-21 01:41:21 +00:00
|
|
|
);
|
|
|
|
hugoBin = `${hugoExtractedFolder}/hugo`;
|
|
|
|
}
|
|
|
|
await io.mv(hugoBin, hugoPath);
|
|
|
|
} catch (error) {
|
|
|
|
core.setFailed(error.message);
|
|
|
|
}
|
|
|
|
}
|