Skip to content

Commit d568351

Browse files
authored
Merge pull request #149 from StaticRocket/reviewdog
feat: allow use of local version of vale
2 parents 2690bc9 + d377866 commit d568351

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ block. For example:
8484

8585
> NOTE: The provided version must be `>= 2.16.0`.
8686

87-
Specify the Vale CLI version to use.
87+
Specify the Vale CLI version to use. If `none`, any preinstalled version of vale
88+
is used.
8889

8990
```yaml
9091
with:

lib/install.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3737
Object.defineProperty(exports, "__esModule", { value: true });
3838
exports.installReviewDog = exports.installLint = void 0;
3939
const core = __importStar(require("@actions/core"));
40+
const exec = __importStar(require("@actions/exec"));
4041
const tc = __importStar(require("@actions/tool-cache"));
4142
const node_fetch_1 = __importDefault(require("node-fetch"));
4243
const path_1 = __importDefault(require("path"));
4344
const releases = 'https://github.com/errata-ai/vale/releases/download';
4445
const last = 'https://github.com/errata-ai/vale/releases/latest/';
46+
function lookupLint() {
47+
return __awaiter(this, void 0, void 0, function* () {
48+
let path = '';
49+
let stderr = '';
50+
let resp = yield exec.exec('which', ['vale'], {
51+
listeners: {
52+
stdout: (buffer) => (path = buffer.toString().trim()),
53+
stderr: (data) => (stderr += data.toString())
54+
}
55+
});
56+
if (resp !== 0) {
57+
core.setFailed(stderr);
58+
}
59+
core.info(`Using the install at ${path}`);
60+
return path;
61+
});
62+
}
4563
function installLint(version) {
4664
return __awaiter(this, void 0, void 0, function* () {
65+
if (version === 'none') {
66+
core.info(`Assuming a version of vale is already available.`);
67+
return yield lookupLint();
68+
}
4769
core.info(`Installing Vale version '${version}' ...`);
4870
if (version === 'latest') {
4971
const response = yield (0, node_fetch_1.default)(last);

src/install.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
import * as core from '@actions/core';
2+
import * as exec from '@actions/exec';
23
import * as tc from '@actions/tool-cache';
34
import fetch from 'node-fetch';
45
import path from 'path';
56

67
const releases = 'https://github.com/errata-ai/vale/releases/download';
78
const last = 'https://github.com/errata-ai/vale/releases/latest/';
89

10+
async function lookupLint(): Promise<string> {
11+
let path = '';
12+
let stderr = '';
13+
14+
let resp = await exec.exec('which', ['vale'], {
15+
listeners: {
16+
stdout: (buffer: Buffer) => (path = buffer.toString().trim()),
17+
stderr: (data: Buffer) => (stderr += data.toString())
18+
}
19+
});
20+
21+
if (resp !== 0) {
22+
core.setFailed(stderr);
23+
}
24+
25+
core.info(`Using the install at ${path}`)
26+
return path;
27+
}
28+
929
export async function installLint(version: string): Promise<string> {
30+
if (version === 'none') {
31+
core.info(`Assuming a version of vale is already available.`);
32+
return await lookupLint();
33+
}
34+
1035
core.info(`Installing Vale version '${version}' ...`);
1136
if (version === 'latest') {
1237
const response = await fetch(last);

0 commit comments

Comments
 (0)