diff --git a/__tests__/get-os.test.ts b/__tests__/get-os.test.ts index dff6d0c..d30e939 100644 --- a/__tests__/get-os.test.ts +++ b/__tests__/get-os.test.ts @@ -1,18 +1,18 @@ -import getOS from "../src/get-os"; +import getOS from '../src/get-os'; -describe("getOS", () => { - test("test", () => { - expect(getOS("linux")).toBe("Linux"); - expect(getOS("darwin")).toBe("macOS"); - expect(getOS("win32")).toBe("Windows"); +describe('getOS', () => { + test('test', () => { + expect(getOS('linux')).toBe('Linux'); + expect(getOS('darwin')).toBe('macOS'); + expect(getOS('win32')).toBe('Windows'); }); - test("test exception", () => { + test('test exception', () => { // expect(() => { // getOS("win32"); // }).toThrowError("Windows is not supported"); expect(() => { - getOS("centos"); - }).toThrowError("centos is not supported"); + getOS('centos'); + }).toThrowError('centos is not supported'); }); }); diff --git a/__tests__/get-url.test.ts b/__tests__/get-url.test.ts index e07ccb2..118a8f2 100644 --- a/__tests__/get-url.test.ts +++ b/__tests__/get-url.test.ts @@ -1,17 +1,17 @@ -import getURL from "../src/get-url"; +import getURL from '../src/get-url'; -describe("getURL()", () => { - test("test", () => { +describe('getURL()', () => { + test('test', () => { const baseURL = - "https://github.com/gohugoio/hugo/releases/download/v0.58.2"; + '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); + 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); }); // test("test exception", () => { diff --git a/src/get-latest-version.ts b/src/get-latest-version.ts index b82fd0e..b7f9382 100644 --- a/src/get-latest-version.ts +++ b/src/get-latest-version.ts @@ -1,10 +1,10 @@ -const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; +const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; export default function getLatestVersion(): Promise { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); - const url: string = "https://formulae.brew.sh/api/formula/hugo.json"; - xhr.open("GET", url); + const url: string = 'https://formulae.brew.sh/api/formula/hugo.json'; + xhr.open('GET', url); xhr.send(); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { diff --git a/src/get-os.ts b/src/get-os.ts index 08d77f1..ef9d50d 100644 --- a/src/get-os.ts +++ b/src/get-os.ts @@ -1,10 +1,10 @@ export default function getOS(platform: string) { - if (platform === "linux") { - return "Linux"; - } else if (platform === "darwin") { - return "macOS"; - } else if (platform === "win32") { - return "Windows"; + if (platform === 'linux') { + return 'Linux'; + } else if (platform === 'darwin') { + return 'macOS'; + } else if (platform === 'win32') { + return 'Windows'; // throw new Error("Windows is not supported"); } else { throw new Error(`${platform} is not supported`); diff --git a/src/get-url.ts b/src/get-url.ts index 62a5ba1..42bd9af 100644 --- a/src/get-url.ts +++ b/src/get-url.ts @@ -4,27 +4,27 @@ export default function getURL( version: string ): string { const extendedStr = (extended: string) => { - if (extended === "true") { - return "extended_"; + if (extended === 'true') { + return 'extended_'; } else { - return ""; + return ''; // } else { // throw new Error(`Invalid input (extended): ${extended}`); } }; const ext = (os: string) => { - if (os === "Windows") { - return "zip"; + if (os === 'Windows') { + return 'zip'; } else { - return "tar.gz"; + return 'tar.gz'; } }; const hugoName: string = `hugo_${extendedStr( extended )}${version}_${os}-64bit`; - const baseURL: string = "https://github.com/gohugoio/hugo/releases/download"; + const baseURL: string = 'https://github.com/gohugoio/hugo/releases/download'; const url: string = `${baseURL}/v${version}/${hugoName}.${ext(os)}`; return url; diff --git a/src/index.ts b/src/index.ts index 6b09d7f..18be6a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,22 +1,22 @@ -import * as core from "@actions/core"; -import * as exec from "@actions/exec"; -import getLatestVersion from "./get-latest-version"; -import installer from "./installer"; +import * as core from '@actions/core'; +import * as exec from '@actions/exec'; +import getLatestVersion from './get-latest-version'; +import installer from './installer'; // most @actions toolkit packages have async methods async function run() { const dump = async () => { // Show version - await exec.exec("hugo version"); - await exec.exec("go version"); - await exec.exec("git --version"); + await exec.exec('hugo version'); + await exec.exec('go version'); + await exec.exec('git --version'); }; try { - const hugoVersion: string = core.getInput("hugo-version"); + const hugoVersion: string = core.getInput('hugo-version'); console.log(`Hugo version: ${hugoVersion}`); - if (hugoVersion === "" || hugoVersion === "latest") { + if (hugoVersion === '' || hugoVersion === 'latest') { getLatestVersion().then( async function(latestVersion): Promise { await installer(latestVersion); diff --git a/src/installer.ts b/src/installer.ts index e955db6..517f4ef 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -1,12 +1,12 @@ -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"; +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'; export default async function installer(version: string) { try { - const extended: string = core.getInput("extended"); + const extended: string = core.getInput('extended'); console.log(`Hugo extended: ${extended}`); const osName: string = getOS(process.platform); @@ -21,17 +21,17 @@ export default async function installer(version: string) { // Download and extract Hugo binary const hugoAssets: string = await tc.downloadTool(hugoURL); - let hugoBin: string = ""; - if (osName === "Windows") { + let hugoBin: string = ''; + if (osName === 'Windows') { const hugoExtractedFolder: string = await tc.extractZip( hugoAssets, - "/tmp" + '/tmp' ); hugoBin = `${hugoExtractedFolder}/hugo.exe`; } else { const hugoExtractedFolder: string = await tc.extractTar( hugoAssets, - "/tmp" + '/tmp' ); hugoBin = `${hugoExtractedFolder}/hugo`; }