diff --git a/__tests__/get-url.test.js b/__tests__/get-url.test.js new file mode 100644 index 0000000..9f0fa35 --- /dev/null +++ b/__tests__/get-url.test.js @@ -0,0 +1,15 @@ +const getURL = require("../lib/get-url"); + +describe("getURL()", () => { + test("test", () => { + const baseURL = "https://github.com/gohugoio/hugo/releases/download/v0.58.2"; + const urlLinux = `${baseURL}/hugo_0.58.2_Linux-64bit.tar.gz`; + const urlLinuxExtended = `${baseURL}/hugo_extended_0.58.2_Linux-64bit.tar.gz`; + const urlMacOS = `${baseURL}/hugo_0.58.2_macOS-64bit.tar.gz`; + const urlWindows = `${baseURL}/hugo_0.58.2_Windows-64bit.zip`; + expect(getURL("Linux", false, "0.58.2")).toBe(urlLinux); + expect(getURL("Linux", true, "0.58.2")).toBe(urlLinuxExtended); + expect(getURL("macOS", false, "0.58.2")).toBe(urlMacOS); + expect(getURL("Windows", false, "0.58.2")).toBe(urlWindows); + }); +}); diff --git a/lib/get-url.js b/lib/get-url.js new file mode 100644 index 0000000..c3ecf6d --- /dev/null +++ b/lib/get-url.js @@ -0,0 +1,19 @@ +function getURL(os, extended, version) { + let extendedStr = ""; + let ext = "tar.gz"; + + if (extended === true) { + extendedStr = "extended_"; + } + + if (os === "Windows") { + ext = "zip"; + } + + const hugoName = `hugo_${extendedStr}${version}_${os}-64bit`; + const url = `https://github.com/gohugoio/hugo/releases/download/v${version}/${hugoName}.${ext}`; + + return url; +} + +module.exports = getURL; diff --git a/lib/index.js b/lib/index.js index d33c8e0..63d13cd 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,6 +3,7 @@ const tc = require("@actions/tool-cache"); const io = require("@actions/io"); const exec = require("@actions/exec"); const getOS = require("./get-os"); +const getURL = require("./get-url"); const getLatestVersion = require("./get-latest-version"); // most @actions toolkit packages have async methods @@ -18,18 +19,11 @@ async function run() { const extended = core.getInput("extended"); console.log(`Hugo extended: ${extended}`); - let extendedStr = ""; - if (extended === "true") { - extendedStr = "extended_"; - } const osName = getOS(process.platform); console.log(`Operating System: ${osName}`); - const hugoName = `hugo_${extendedStr}${hugoVersion}_${osName}-64bit`; - core.debug(`hugoName: ${hugoName}`); - - const hugoURL = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/${hugoName}.tar.gz`; + const hugoURL = getURL(osName, extended, hugoVersion); core.debug(`hugoURL: ${hugoURL}`); const hugoPath = `${process.env.HOME}/bin`; diff --git a/package.json b/package.json index 452cdc2..14e603b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "scripts": { "lint": "eslint ./lib/**/*", - "test": "jest", + "test": "jest --coverage --verbose", "build": "npm prune --production" }, "repository": {