refactor: slpit installer.js
This commit is contained in:
parent
3512622901
commit
67d5fb9f50
2 changed files with 36 additions and 28 deletions
30
lib/index.js
30
lib/index.js
|
|
@ -1,10 +1,7 @@
|
||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const tc = require("@actions/tool-cache");
|
|
||||||
const io = require("@actions/io");
|
|
||||||
const exec = require("@actions/exec");
|
const exec = require("@actions/exec");
|
||||||
const getOS = require("./get-os");
|
|
||||||
const getURL = require("./get-url");
|
|
||||||
const getLatestVersion = require("./get-latest-version");
|
const getLatestVersion = require("./get-latest-version");
|
||||||
|
const installer = require("./installer");
|
||||||
|
|
||||||
// most @actions toolkit packages have async methods
|
// most @actions toolkit packages have async methods
|
||||||
async function run() {
|
async function run() {
|
||||||
|
|
@ -17,30 +14,7 @@ async function run() {
|
||||||
}
|
}
|
||||||
console.log(`Hugo version: ${hugoVersion}`);
|
console.log(`Hugo version: ${hugoVersion}`);
|
||||||
|
|
||||||
const extended = core.getInput("extended");
|
await installer(hugoVersion);
|
||||||
console.log(`Hugo extended: ${extended}`);
|
|
||||||
|
|
||||||
const osName = getOS(process.platform);
|
|
||||||
console.log(`Operating System: ${osName}`);
|
|
||||||
|
|
||||||
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 hugoAssets = await tc.downloadTool(hugoURL);
|
|
||||||
let hugoBin = "";
|
|
||||||
if (osName === "Windows") {
|
|
||||||
const hugoExtractedFolder = await tc.extractZip(hugoAssets, "/tmp");
|
|
||||||
hugoBin = `${hugoExtractedFolder}/hugo.exe`;
|
|
||||||
} else {
|
|
||||||
const hugoExtractedFolder = await tc.extractTar(hugoAssets, "/tmp");
|
|
||||||
hugoBin = `${hugoExtractedFolder}/hugo`;
|
|
||||||
}
|
|
||||||
await io.mv(hugoBin, hugoPath);
|
|
||||||
|
|
||||||
// Show version
|
// Show version
|
||||||
await exec.exec("hugo version");
|
await exec.exec("hugo version");
|
||||||
|
|
|
||||||
34
lib/installer.js
Normal file
34
lib/installer.js
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
const core = require("@actions/core");
|
||||||
|
const tc = require("@actions/tool-cache");
|
||||||
|
const io = require("@actions/io");
|
||||||
|
const getOS = require("./get-os");
|
||||||
|
const getURL = require("./get-url");
|
||||||
|
|
||||||
|
async function installer(version) {
|
||||||
|
const extended = core.getInput("extended");
|
||||||
|
console.log(`Hugo extended: ${extended}`);
|
||||||
|
|
||||||
|
const osName = getOS(process.platform);
|
||||||
|
console.log(`Operating System: ${osName}`);
|
||||||
|
|
||||||
|
const hugoURL = getURL(osName, extended, version);
|
||||||
|
core.debug(`hugoURL: ${hugoURL}`);
|
||||||
|
|
||||||
|
const hugoPath = `${process.env.HOME}/bin`;
|
||||||
|
await io.mkdirP(hugoPath);
|
||||||
|
core.addPath(hugoPath);
|
||||||
|
|
||||||
|
// Download and extract Hugo binary
|
||||||
|
const hugoAssets = await tc.downloadTool(hugoURL);
|
||||||
|
let hugoBin = "";
|
||||||
|
if (osName === "Windows") {
|
||||||
|
const hugoExtractedFolder = await tc.extractZip(hugoAssets, "/tmp");
|
||||||
|
hugoBin = `${hugoExtractedFolder}/hugo.exe`;
|
||||||
|
} else {
|
||||||
|
const hugoExtractedFolder = await tc.extractTar(hugoAssets, "/tmp");
|
||||||
|
hugoBin = `${hugoExtractedFolder}/hugo`;
|
||||||
|
}
|
||||||
|
await io.mv(hugoBin, hugoPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = installer;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue