diff --git a/__tests__/get-os.test.js b/__tests__/get-os.test.js new file mode 100644 index 0000000..3254a98 --- /dev/null +++ b/__tests__/get-os.test.js @@ -0,0 +1,17 @@ +const getOS = require("../lib/get-os"); + +describe("getOS", () => { + test("test", () => { + expect(getOS("linux")).toBe("Linux"); + expect(getOS("darwin")).toBe("macOS"); + }); + + test("test exception", () => { + expect(() => { + getOS("win32"); + }).toThrowError("Windows is not supported"); + expect(() => { + getOS("centos"); + }).toThrowError("centos is not supported"); + }); +}); diff --git a/__tests__/index.test.js b/__tests__/index.test.js deleted file mode 100644 index 9725109..0000000 --- a/__tests__/index.test.js +++ /dev/null @@ -1,23 +0,0 @@ -const wait = require('./wait'); -const process = require('process'); -const cp = require('child_process'); -const path = require('path'); - -test('throws invalid number', async() => { - await expect(wait('foo')).rejects.toThrow('milleseconds not a number'); -}); - -test('wait 500 ms', async() => { - const start = new Date(); - await wait(500); - const end = new Date(); - var delta = Math.abs(end - start); - expect(delta).toBeGreaterThan(450); -}); - -// shows how the runner will run a javascript action with env / stdout protocol -test('test runs', () => { - process.env['INPUT_MILLISECONDS'] = 500; - const ip = path.join(__dirname, 'index.js'); - console.log(cp.execSync(`node ${ip}`).toString()); -}) diff --git a/lib/get-os.js b/lib/get-os.js new file mode 100644 index 0000000..bd076c3 --- /dev/null +++ b/lib/get-os.js @@ -0,0 +1,13 @@ +function getOS(platform) { + if (platform === "linux") { + return "Linux"; + } else if (platform === "darwin") { + return "macOS"; + } else if (platform === "win32") { + throw new Error("Windows is not supported"); + } else { + throw new Error(`${platform} is not supported`); + } +} + +module.exports = getOS; diff --git a/lib/index.js b/lib/index.js index d90048a..8031f90 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,6 +2,7 @@ const core = require("@actions/core"); const tc = require("@actions/tool-cache"); const io = require("@actions/io"); const exec = require("@actions/exec"); +const getOS = require("./get-os"); const getLatestVersion = require("./get-latest-version"); // most @actions toolkit packages have async methods @@ -22,9 +23,10 @@ async function run() { extendedStr = "extended_"; } - console.log(`Operating System: ${process.platform}`); + const osName = getOS(process.platform); + console.log(`Operating System: ${osName}`); - const hugoName = `hugo_${extendedStr}${hugoVersion}_Linux-64bit`; + 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`; diff --git a/package-lock.json b/package-lock.json index 1cd7c8b..6ce03ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "hugo-action", - "version": "0.1.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": {