Skip to content

Commit

Permalink
feat: add support for arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
tvcsantos committed Jan 31, 2025
1 parent 2690bc9 commit 82ea885
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 37 deletions.
12 changes: 6 additions & 6 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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,
Expand All @@ -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');
Expand All @@ -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 {
Expand All @@ -121,7 +121,7 @@ function get(tok, dir) {
workspace: dir,
exePath: localVale,
args: args,
reviewdogPath: localReviewDog,
reviewdogPath: localReviewDog
};
});
}
Expand Down
56 changes: 49 additions & 7 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 10 additions & 9 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down Expand Up @@ -50,8 +48,11 @@ function logIfDebug(msg: string) {
*/
export async function get(tok: string, dir: string): Promise<Input> {
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'], {
Expand Down Expand Up @@ -79,7 +80,7 @@ export async function get(tok: string, dir: string): Promise<Input> {

let args: string[] = [
`--output=${path.resolve(__dirname, 'rdjsonl.tmpl')}`,
...parse(valeFlags),
...parse(valeFlags)
];

// Figure out what we're supposed to lint:
Expand All @@ -90,7 +91,7 @@ export async function get(tok: string, dir: string): Promise<Input> {
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 {
Expand All @@ -113,6 +114,6 @@ export async function get(tok: string, dir: string): Promise<Input> {
workspace: dir,
exePath: localVale,
args: args,
reviewdogPath: localReviewDog,
reviewdogPath: localReviewDog
};
}
79 changes: 71 additions & 8 deletions src/install.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,85 @@
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<string> {
const supportedSystem = getSupportedSystem();
core.info(`Installing Vale version '${version}' ...`);
if (version === 'latest') {
const response = await 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 = 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);
Expand All @@ -31,19 +90,23 @@ export async function installLint(version: string): Promise<string> {
return lintPath;
}

export async function installReviewDog(version: string, url?: string): Promise<string> {
export async function installReviewDog(
version: string,
url?: string
): Promise<string> {
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);

let extractedDir = '';

const args = ['xz'];
if (process.platform.toString() != 'darwin') {
if (os != RunnerOS.MAC) {
args.push('--overwrite');
}

Expand Down
11 changes: 5 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import * as exec from '@actions/exec';
import * as path from 'path';
import * as input from './input';



/**
* These environment variables are exposed for GitHub Actions.
*
* See https://bit.ly/2WlFUD7 for more information.
*/
const { GITHUB_WORKSPACE } = process.env;
const {GITHUB_WORKSPACE} = process.env;

export async function run(actionInput: input.Input): Promise<void> {
const workdir = core.getInput('workdir') || '.';
Expand All @@ -31,13 +29,13 @@ export async function run(actionInput: input.Input): Promise<void> {
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.
Expand All @@ -58,7 +56,8 @@ export async function run(actionInput: input.Input): Promise<void> {
`-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'
}`
],
{
Expand Down

0 comments on commit 82ea885

Please sign in to comment.