Skip to content

Commit 82ea885

Browse files
committed
feat: add support for arm64
1 parent 2690bc9 commit 82ea885

6 files changed

Lines changed: 142 additions & 37 deletions

File tree

lib/input.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const path = __importStar(require("path"));
4040
const install_1 = require("./install");
4141
function parse(flags) {
4242
flags = flags.trim();
43-
if (flags === "") {
43+
if (flags === '') {
4444
return [];
4545
}
4646
// TODO: need to simulate bash?
@@ -64,8 +64,8 @@ function logIfDebug(msg) {
6464
function get(tok, dir) {
6565
return __awaiter(this, void 0, void 0, function* () {
6666
const localVale = yield (0, install_1.installLint)(core.getInput('version'));
67-
const localReviewDog = yield (0, install_1.installReviewDog)("0.17.0", core.getInput('reviewdog_url'));
68-
const valeFlags = core.getInput("vale_flags");
67+
const localReviewDog = yield (0, install_1.installReviewDog)('0.17.0', core.getInput('reviewdog_url'));
68+
const valeFlags = core.getInput('vale_flags');
6969
let version = '';
7070
yield exec.exec(localVale, ['-v'], {
7171
silent: true,
@@ -89,7 +89,7 @@ function get(tok, dir) {
8989
}
9090
let args = [
9191
`--output=${path.resolve(__dirname, 'rdjsonl.tmpl')}`,
92-
...parse(valeFlags),
92+
...parse(valeFlags)
9393
];
9494
// Figure out what we're supposed to lint:
9595
const files = core.getInput('files');
@@ -100,7 +100,7 @@ function get(tok, dir) {
100100
else if (fs.existsSync(path.resolve(dir, files))) {
101101
args.push(files);
102102
}
103-
else if (delim !== "") {
103+
else if (delim !== '') {
104104
args = args.concat(files.split(delim));
105105
}
106106
else {
@@ -121,7 +121,7 @@ function get(tok, dir) {
121121
workspace: dir,
122122
exePath: localVale,
123123
args: args,
124-
reviewdogPath: localReviewDog,
124+
reviewdogPath: localReviewDog
125125
};
126126
});
127127
}

lib/install.js

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,68 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3535
return (mod && mod.__esModule) ? mod : { "default": mod };
3636
};
3737
Object.defineProperty(exports, "__esModule", { value: true });
38-
exports.installReviewDog = exports.installLint = void 0;
38+
exports.installReviewDog = exports.installLint = exports.getSupportedSystem = void 0;
3939
const core = __importStar(require("@actions/core"));
4040
const tc = __importStar(require("@actions/tool-cache"));
41-
const node_fetch_1 = __importDefault(require("node-fetch"));
4241
const path_1 = __importDefault(require("path"));
4342
const releases = 'https://github.com/errata-ai/vale/releases/download';
4443
const last = 'https://github.com/errata-ai/vale/releases/latest/';
44+
var RunnerOS;
45+
(function (RunnerOS) {
46+
RunnerOS["LINUX"] = "Linux";
47+
RunnerOS["MAC"] = "macOS";
48+
RunnerOS["WINDOWS"] = "Windows";
49+
})(RunnerOS || (RunnerOS = {}));
50+
var RunnerArch;
51+
(function (RunnerArch) {
52+
RunnerArch["X86"] = "X86";
53+
RunnerArch["X64"] = "X64";
54+
RunnerArch["ARM"] = "ARM";
55+
RunnerArch["ARM64"] = "ARM64";
56+
})(RunnerArch || (RunnerArch = {}));
57+
const os = process.env.RUNNER_OS;
58+
const arch = process.env.RUNNER_ARCH;
59+
const system = { os, arch };
60+
const supportedSystems = [
61+
{
62+
system: { os: RunnerOS.LINUX, arch: RunnerArch.X64 },
63+
tools: {
64+
vale: 'Linux_64-bit.tar.gz',
65+
reviewdog: 'Linux_x86_64.tar.gz'
66+
}
67+
},
68+
{
69+
system: { os: RunnerOS.LINUX, arch: RunnerArch.ARM64 },
70+
tools: {
71+
vale: 'Linux_arm64.tar.gz',
72+
reviewdog: 'Linux_arm64.tar.gz'
73+
}
74+
}
75+
];
76+
function getSupportedSystem() {
77+
for (const supportedSystem of supportedSystems) {
78+
if (supportedSystem.system.os === system.os && supportedSystem.system.arch === system.arch) {
79+
return supportedSystem;
80+
}
81+
}
82+
throw new Error(`Unsupported system: ${JSON.stringify(system)}`);
83+
}
84+
exports.getSupportedSystem = getSupportedSystem;
4585
function installLint(version) {
4686
return __awaiter(this, void 0, void 0, function* () {
87+
const supportedSystem = getSupportedSystem();
4788
core.info(`Installing Vale version '${version}' ...`);
4889
if (version === 'latest') {
49-
const response = yield (0, node_fetch_1.default)(last);
90+
const response = yield fetch(last);
5091
const vs = response.url;
5192
const parts = vs.split(`/`);
5293
version = parts[parts.length - 1].substring(1);
5394
}
54-
const url = releases + `/v${version}/vale_${version}_Linux_64-bit.tar.gz`;
95+
const url = releases + `/v${version}/vale_${version}_${supportedSystem.tools.vale}`;
5596
const archivePath = yield tc.downloadTool(url);
5697
let extractedDir = '';
5798
const args = ['xz'];
58-
if (process.platform.toString() != 'darwin') {
99+
if (os != RunnerOS.MAC) {
59100
args.push('--overwrite');
60101
}
61102
extractedDir = yield tc.extractTar(archivePath, process.env.HOME, args);
@@ -67,14 +108,15 @@ function installLint(version) {
67108
exports.installLint = installLint;
68109
function installReviewDog(version, url) {
69110
return __awaiter(this, void 0, void 0, function* () {
111+
const supportedSystem = getSupportedSystem();
70112
core.info(`Installing ReviewDog version '${version}' ...`);
71113
if (!url) {
72-
url = `https://github.com/reviewdog/reviewdog/releases/download/v${version}/reviewdog_${version}_Linux_x86_64.tar.gz`;
114+
url = `https://github.com/reviewdog/reviewdog/releases/download/v${version}/reviewdog_${version}_${supportedSystem.tools.reviewdog}`;
73115
}
74116
const archivePath = yield tc.downloadTool(url);
75117
let extractedDir = '';
76118
const args = ['xz'];
77-
if (process.platform.toString() != 'darwin') {
119+
if (os != RunnerOS.MAC) {
78120
args.push('--overwrite');
79121
}
80122
extractedDir = yield tc.extractTar(archivePath, process.env.HOME, args);

lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function run(actionInput) {
5454
cwd,
5555
ignoreReturnCode: true,
5656
env: {
57-
"PATH": `${process.env["PATH"]}:/home/runner/.local/share/gem/ruby/3.0.0/bin`
57+
PATH: `${process.env['PATH']}:/home/runner/.local/share/gem/ruby/3.0.0/bin`
5858
}
5959
});
6060
const vale_code = output.exitCode;

src/input.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
33
import * as fs from 'fs';
44
import * as path from 'path';
5-
import { installLint, installReviewDog } from './install';
6-
7-
5+
import {installLint, installReviewDog} from './install';
86

97
export function parse(flags: string): string[] {
108
flags = flags.trim();
11-
if (flags === "") {
9+
if (flags === '') {
1210
return [];
1311
}
1412

@@ -50,8 +48,11 @@ function logIfDebug(msg: string) {
5048
*/
5149
export async function get(tok: string, dir: string): Promise<Input> {
5250
const localVale = await installLint(core.getInput('version'));
53-
const localReviewDog = await installReviewDog("0.17.0", core.getInput('reviewdog_url'));
54-
const valeFlags = core.getInput("vale_flags");
51+
const localReviewDog = await installReviewDog(
52+
'0.17.0',
53+
core.getInput('reviewdog_url')
54+
);
55+
const valeFlags = core.getInput('vale_flags');
5556

5657
let version = '';
5758
await exec.exec(localVale, ['-v'], {
@@ -79,7 +80,7 @@ export async function get(tok: string, dir: string): Promise<Input> {
7980

8081
let args: string[] = [
8182
`--output=${path.resolve(__dirname, 'rdjsonl.tmpl')}`,
82-
...parse(valeFlags),
83+
...parse(valeFlags)
8384
];
8485

8586
// Figure out what we're supposed to lint:
@@ -90,7 +91,7 @@ export async function get(tok: string, dir: string): Promise<Input> {
9091
args.push('.');
9192
} else if (fs.existsSync(path.resolve(dir, files))) {
9293
args.push(files);
93-
} else if (delim !== "") {
94+
} else if (delim !== '') {
9495
args = args.concat(files.split(delim));
9596
} else {
9697
try {
@@ -113,6 +114,6 @@ export async function get(tok: string, dir: string): Promise<Input> {
113114
workspace: dir,
114115
exePath: localVale,
115116
args: args,
116-
reviewdogPath: localReviewDog,
117+
reviewdogPath: localReviewDog
117118
};
118119
}

src/install.ts

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,85 @@
11
import * as core from '@actions/core';
22
import * as tc from '@actions/tool-cache';
3-
import fetch from 'node-fetch';
43
import path from 'path';
54

65
const releases = 'https://github.com/errata-ai/vale/releases/download';
76
const last = 'https://github.com/errata-ai/vale/releases/latest/';
87

8+
enum RunnerOS {
9+
LINUX = 'Linux',
10+
MAC = 'macOS',
11+
WINDOWS = 'Windows'
12+
}
13+
14+
enum RunnerArch {
15+
X86 = 'X86',
16+
X64 = 'X64',
17+
ARM = 'ARM',
18+
ARM64 = 'ARM64'
19+
}
20+
21+
const os = process.env.RUNNER_OS as RunnerOS;
22+
const arch = process.env.RUNNER_ARCH as RunnerArch;
23+
const system: System = {os, arch};
24+
25+
type System = {
26+
os: RunnerOS;
27+
arch: RunnerArch;
28+
};
29+
30+
type SupportedSystem = {
31+
system: System;
32+
tools: Tools;
33+
};
34+
35+
type Tools = {
36+
vale: string;
37+
reviewdog: string;
38+
};
39+
40+
const supportedSystems: SupportedSystem[] = [
41+
{
42+
system: {os: RunnerOS.LINUX, arch: RunnerArch.X64},
43+
tools: {
44+
vale: 'Linux_64-bit.tar.gz',
45+
reviewdog: 'Linux_x86_64.tar.gz'
46+
}
47+
},
48+
{
49+
system: {os: RunnerOS.LINUX, arch: RunnerArch.ARM64},
50+
tools: {
51+
vale: 'Linux_arm64.tar.gz',
52+
reviewdog: 'Linux_arm64.tar.gz'
53+
}
54+
}
55+
];
56+
57+
export function getSupportedSystem(): SupportedSystem {
58+
for (const supportedSystem of supportedSystems) {
59+
if (supportedSystem.system.os === system.os && supportedSystem.system.arch === system.arch) {
60+
return supportedSystem;
61+
}
62+
}
63+
throw new Error(`Unsupported system: ${JSON.stringify(system)}`);
64+
}
65+
966
export async function installLint(version: string): Promise<string> {
67+
const supportedSystem = getSupportedSystem();
1068
core.info(`Installing Vale version '${version}' ...`);
1169
if (version === 'latest') {
1270
const response = await fetch(last);
1371
const vs = response.url;
1472
const parts = vs.split(`/`);
1573
version = parts[parts.length - 1].substring(1);
1674
}
17-
const url = releases + `/v${version}/vale_${version}_Linux_64-bit.tar.gz`;
75+
const url =
76+
releases + `/v${version}/vale_${version}_${supportedSystem.tools.vale}`;
1877
const archivePath = await tc.downloadTool(url);
1978

2079
let extractedDir = '';
2180

2281
const args = ['xz'];
23-
if (process.platform.toString() != 'darwin') {
82+
if (os != RunnerOS.MAC) {
2483
args.push('--overwrite');
2584
}
2685
extractedDir = await tc.extractTar(archivePath, process.env.HOME, args);
@@ -31,19 +90,23 @@ export async function installLint(version: string): Promise<string> {
3190
return lintPath;
3291
}
3392

34-
export async function installReviewDog(version: string, url?: string): Promise<string> {
93+
export async function installReviewDog(
94+
version: string,
95+
url?: string
96+
): Promise<string> {
97+
const supportedSystem = getSupportedSystem();
3598
core.info(`Installing ReviewDog version '${version}' ...`);
36-
37-
if (!url){
38-
url = `https://github.com/reviewdog/reviewdog/releases/download/v${version}/reviewdog_${version}_Linux_x86_64.tar.gz`;
99+
100+
if (!url) {
101+
url = `https://github.com/reviewdog/reviewdog/releases/download/v${version}/reviewdog_${version}_${supportedSystem.tools.reviewdog}`;
39102
}
40103

41104
const archivePath = await tc.downloadTool(url);
42105

43106
let extractedDir = '';
44107

45108
const args = ['xz'];
46-
if (process.platform.toString() != 'darwin') {
109+
if (os != RunnerOS.MAC) {
47110
args.push('--overwrite');
48111
}
49112

src/main.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import * as exec from '@actions/exec';
33
import * as path from 'path';
44
import * as input from './input';
55

6-
7-
86
/**
97
* These environment variables are exposed for GitHub Actions.
108
*
119
* See https://bit.ly/2WlFUD7 for more information.
1210
*/
13-
const { GITHUB_WORKSPACE } = process.env;
11+
const {GITHUB_WORKSPACE} = process.env;
1412

1513
export async function run(actionInput: input.Input): Promise<void> {
1614
const workdir = core.getInput('workdir') || '.';
@@ -31,13 +29,13 @@ export async function run(actionInput: input.Input): Promise<void> {
3129
cwd,
3230
ignoreReturnCode: true,
3331
env: {
34-
"PATH": `${process.env["PATH"]}:/home/runner/.local/share/gem/ruby/3.0.0/bin`
32+
PATH: `${process.env['PATH']}:/home/runner/.local/share/gem/ruby/3.0.0/bin`
3533
}
3634
}
3735
);
3836

3937
const vale_code = output.exitCode;
40-
'Vale return code: ${vale_code}'
38+
'Vale return code: ${vale_code}';
4139
// Check for fatal runtime errors only (exit code 2)
4240
// These aren't linting errors, but ones that will come
4341
// about from missing or bad configuration files, etc.
@@ -58,7 +56,8 @@ export async function run(actionInput: input.Input): Promise<void> {
5856
`-reporter=${core.getInput('reporter')}`,
5957
`-fail-on-error=${should_fail}`,
6058
`-filter-mode=${core.getInput('filter_mode')}`,
61-
`-level=${vale_code == 1 && should_fail === 'true' ? 'error' : 'info'
59+
`-level=${
60+
vale_code == 1 && should_fail === 'true' ? 'error' : 'info'
6261
}`
6362
],
6463
{

0 commit comments

Comments
 (0)