diff --git a/lib/input.js b/lib/input.js index ba86c8c0..0b27dc9a 100644 --- a/lib/input.js +++ b/lib/input.js @@ -40,7 +40,7 @@ const path = __importStar(require("path")); const install_1 = require("./install"); function parse(flags) { flags = flags.trim(); - if (flags === "") { + if (flags === '') { return []; } // TODO: need to simulate bash? @@ -64,8 +64,8 @@ function logIfDebug(msg) { function get(tok, dir) { return __awaiter(this, void 0, void 0, function* () { const localVale = yield (0, install_1.installLint)(core.getInput('version')); - const localReviewDog = yield (0, install_1.installReviewDog)("0.17.0", core.getInput('reviewdog_url')); - const valeFlags = core.getInput("vale_flags"); + const localReviewDog = yield (0, install_1.installReviewDog)('0.17.0', core.getInput('reviewdog_url')); + const valeFlags = core.getInput('vale_flags'); let version = ''; yield exec.exec(localVale, ['-v'], { silent: true, @@ -89,7 +89,7 @@ function get(tok, dir) { } let args = [ `--output=${path.resolve(__dirname, 'rdjsonl.tmpl')}`, - ...parse(valeFlags), + ...parse(valeFlags) ]; // Figure out what we're supposed to lint: const files = core.getInput('files'); @@ -100,7 +100,7 @@ function get(tok, dir) { else if (fs.existsSync(path.resolve(dir, files))) { args.push(files); } - else if (delim !== "") { + else if (delim !== '') { args = args.concat(files.split(delim)); } else { @@ -121,7 +121,7 @@ function get(tok, dir) { workspace: dir, exePath: localVale, args: args, - reviewdogPath: localReviewDog, + reviewdogPath: localReviewDog }; }); } diff --git a/lib/install.js b/lib/install.js index 03f381e9..2f9aa17c 100644 --- a/lib/install.js +++ b/lib/install.js @@ -35,27 +35,68 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.installReviewDog = exports.installLint = void 0; +exports.installReviewDog = exports.installLint = exports.getSupportedSystem = void 0; const core = __importStar(require("@actions/core")); const tc = __importStar(require("@actions/tool-cache")); -const node_fetch_1 = __importDefault(require("node-fetch")); const path_1 = __importDefault(require("path")); const releases = 'https://github.com/errata-ai/vale/releases/download'; const last = 'https://github.com/errata-ai/vale/releases/latest/'; +var RunnerOS; +(function (RunnerOS) { + RunnerOS["LINUX"] = "Linux"; + RunnerOS["MAC"] = "macOS"; + RunnerOS["WINDOWS"] = "Windows"; +})(RunnerOS || (RunnerOS = {})); +var RunnerArch; +(function (RunnerArch) { + RunnerArch["X86"] = "X86"; + RunnerArch["X64"] = "X64"; + RunnerArch["ARM"] = "ARM"; + RunnerArch["ARM64"] = "ARM64"; +})(RunnerArch || (RunnerArch = {})); +const os = process.env.RUNNER_OS; +const arch = process.env.RUNNER_ARCH; +const system = { os, arch }; +const supportedSystems = [ + { + system: { os: RunnerOS.LINUX, arch: RunnerArch.X64 }, + tools: { + vale: 'Linux_64-bit.tar.gz', + reviewdog: 'Linux_x86_64.tar.gz' + } + }, + { + system: { os: RunnerOS.LINUX, arch: RunnerArch.ARM64 }, + tools: { + vale: 'Linux_arm64.tar.gz', + reviewdog: 'Linux_arm64.tar.gz' + } + } +]; +function getSupportedSystem() { + for (const supportedSystem of supportedSystems) { + if (supportedSystem.system.os === system.os && supportedSystem.system.arch === system.arch) { + return supportedSystem; + } + } + throw new Error(`Unsupported system: ${JSON.stringify(system)}`); +} +exports.getSupportedSystem = getSupportedSystem; function installLint(version) { return __awaiter(this, void 0, void 0, function* () { + const supportedSystem = getSupportedSystem(); core.info(`Installing Vale version '${version}' ...`); if (version === 'latest') { - const response = yield (0, node_fetch_1.default)(last); + const response = yield fetch(last); const vs = response.url; const parts = vs.split(`/`); version = parts[parts.length - 1].substring(1); } - const url = releases + `/v${version}/vale_${version}_Linux_64-bit.tar.gz`; + const url = releases + `/v${version}/vale_${version}_${supportedSystem.tools.vale}`; const archivePath = yield tc.downloadTool(url); let extractedDir = ''; const args = ['xz']; - if (process.platform.toString() != 'darwin') { + if (os != RunnerOS.MAC) { args.push('--overwrite'); } extractedDir = yield tc.extractTar(archivePath, process.env.HOME, args); @@ -67,14 +108,15 @@ function installLint(version) { exports.installLint = installLint; function installReviewDog(version, url) { return __awaiter(this, void 0, void 0, function* () { + const supportedSystem = getSupportedSystem(); core.info(`Installing ReviewDog version '${version}' ...`); if (!url) { - url = `https://github.com/reviewdog/reviewdog/releases/download/v${version}/reviewdog_${version}_Linux_x86_64.tar.gz`; + url = `https://github.com/reviewdog/reviewdog/releases/download/v${version}/reviewdog_${version}_${supportedSystem.tools.reviewdog}`; } const archivePath = yield tc.downloadTool(url); let extractedDir = ''; const args = ['xz']; - if (process.platform.toString() != 'darwin') { + if (os != RunnerOS.MAC) { args.push('--overwrite'); } extractedDir = yield tc.extractTar(archivePath, process.env.HOME, args); diff --git a/lib/main.js b/lib/main.js index 2988818f..1cbb57c8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -54,7 +54,7 @@ function run(actionInput) { cwd, ignoreReturnCode: true, env: { - "PATH": `${process.env["PATH"]}:/home/runner/.local/share/gem/ruby/3.0.0/bin` + PATH: `${process.env['PATH']}:/home/runner/.local/share/gem/ruby/3.0.0/bin` } }); const vale_code = output.exitCode; diff --git a/src/input.ts b/src/input.ts index 35583d3b..b4b2f741 100644 --- a/src/input.ts +++ b/src/input.ts @@ -2,13 +2,11 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; import * as fs from 'fs'; import * as path from 'path'; -import { installLint, installReviewDog } from './install'; - - +import {installLint, installReviewDog} from './install'; export function parse(flags: string): string[] { flags = flags.trim(); - if (flags === "") { + if (flags === '') { return []; } @@ -50,8 +48,11 @@ function logIfDebug(msg: string) { */ export async function get(tok: string, dir: string): Promise { const localVale = await installLint(core.getInput('version')); - const localReviewDog = await installReviewDog("0.17.0", core.getInput('reviewdog_url')); - const valeFlags = core.getInput("vale_flags"); + const localReviewDog = await installReviewDog( + '0.17.0', + core.getInput('reviewdog_url') + ); + const valeFlags = core.getInput('vale_flags'); let version = ''; await exec.exec(localVale, ['-v'], { @@ -79,7 +80,7 @@ export async function get(tok: string, dir: string): Promise { let args: string[] = [ `--output=${path.resolve(__dirname, 'rdjsonl.tmpl')}`, - ...parse(valeFlags), + ...parse(valeFlags) ]; // Figure out what we're supposed to lint: @@ -90,7 +91,7 @@ export async function get(tok: string, dir: string): Promise { args.push('.'); } else if (fs.existsSync(path.resolve(dir, files))) { args.push(files); - } else if (delim !== "") { + } else if (delim !== '') { args = args.concat(files.split(delim)); } else { try { @@ -113,6 +114,6 @@ export async function get(tok: string, dir: string): Promise { workspace: dir, exePath: localVale, args: args, - reviewdogPath: localReviewDog, + reviewdogPath: localReviewDog }; } diff --git a/src/install.ts b/src/install.ts index 1026b574..d059af30 100644 --- a/src/install.ts +++ b/src/install.ts @@ -1,12 +1,70 @@ import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; -import fetch from 'node-fetch'; import path from 'path'; const releases = 'https://github.com/errata-ai/vale/releases/download'; const last = 'https://github.com/errata-ai/vale/releases/latest/'; +enum RunnerOS { + LINUX = 'Linux', + MAC = 'macOS', + WINDOWS = 'Windows' +} + +enum RunnerArch { + X86 = 'X86', + X64 = 'X64', + ARM = 'ARM', + ARM64 = 'ARM64' +} + +const os = process.env.RUNNER_OS as RunnerOS; +const arch = process.env.RUNNER_ARCH as RunnerArch; +const system: System = {os, arch}; + +type System = { + os: RunnerOS; + arch: RunnerArch; +}; + +type SupportedSystem = { + system: System; + tools: Tools; +}; + +type Tools = { + vale: string; + reviewdog: string; +}; + +const supportedSystems: SupportedSystem[] = [ + { + system: {os: RunnerOS.LINUX, arch: RunnerArch.X64}, + tools: { + vale: 'Linux_64-bit.tar.gz', + reviewdog: 'Linux_x86_64.tar.gz' + } + }, + { + system: {os: RunnerOS.LINUX, arch: RunnerArch.ARM64}, + tools: { + vale: 'Linux_arm64.tar.gz', + reviewdog: 'Linux_arm64.tar.gz' + } + } +]; + +export function getSupportedSystem(): SupportedSystem { + for (const supportedSystem of supportedSystems) { + if (supportedSystem.system.os === system.os && supportedSystem.system.arch === system.arch) { + return supportedSystem; + } + } + throw new Error(`Unsupported system: ${JSON.stringify(system)}`); +} + export async function installLint(version: string): Promise { + const supportedSystem = getSupportedSystem(); core.info(`Installing Vale version '${version}' ...`); if (version === 'latest') { const response = await fetch(last); @@ -14,13 +72,14 @@ export async function installLint(version: string): Promise { const parts = vs.split(`/`); version = parts[parts.length - 1].substring(1); } - const url = releases + `/v${version}/vale_${version}_Linux_64-bit.tar.gz`; + const url = + releases + `/v${version}/vale_${version}_${supportedSystem.tools.vale}`; const archivePath = await tc.downloadTool(url); let extractedDir = ''; const args = ['xz']; - if (process.platform.toString() != 'darwin') { + if (os != RunnerOS.MAC) { args.push('--overwrite'); } extractedDir = await tc.extractTar(archivePath, process.env.HOME, args); @@ -31,11 +90,15 @@ export async function installLint(version: string): Promise { return lintPath; } -export async function installReviewDog(version: string, url?: string): Promise { +export async function installReviewDog( + version: string, + url?: string +): Promise { + const supportedSystem = getSupportedSystem(); core.info(`Installing ReviewDog version '${version}' ...`); - - if (!url){ - url = `https://github.com/reviewdog/reviewdog/releases/download/v${version}/reviewdog_${version}_Linux_x86_64.tar.gz`; + + if (!url) { + url = `https://github.com/reviewdog/reviewdog/releases/download/v${version}/reviewdog_${version}_${supportedSystem.tools.reviewdog}`; } const archivePath = await tc.downloadTool(url); @@ -43,7 +106,7 @@ export async function installReviewDog(version: string, url?: string): Promise { const workdir = core.getInput('workdir') || '.'; @@ -31,13 +29,13 @@ export async function run(actionInput: input.Input): Promise { cwd, ignoreReturnCode: true, env: { - "PATH": `${process.env["PATH"]}:/home/runner/.local/share/gem/ruby/3.0.0/bin` + PATH: `${process.env['PATH']}:/home/runner/.local/share/gem/ruby/3.0.0/bin` } } ); const vale_code = output.exitCode; - 'Vale return code: ${vale_code}' + 'Vale return code: ${vale_code}'; // Check for fatal runtime errors only (exit code 2) // These aren't linting errors, but ones that will come // about from missing or bad configuration files, etc. @@ -58,7 +56,8 @@ export async function run(actionInput: input.Input): Promise { `-reporter=${core.getInput('reporter')}`, `-fail-on-error=${should_fail}`, `-filter-mode=${core.getInput('filter_mode')}`, - `-level=${vale_code == 1 && should_fail === 'true' ? 'error' : 'info' + `-level=${ + vale_code == 1 && should_fail === 'true' ? 'error' : 'info' }` ], {