-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
39 lines (32 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const core = require('@actions/core');
const exec = require('@actions/exec');
const path = require('path');
const linters = core.getInput('linters', { required: true }).split(/[,\s]+/);
const action = core.getInput('action') || 'run';
const run = core.getInput('run', { required: action == 'run' });
const problemMatchersPath = path.resolve(path.join(__dirname, '..', 'problem-matchers'));
async function main() {
const problemMatcherFiles = linters.map(kind => path.join(problemMatchersPath, `${kind}.json`));
const problemMatchers = problemMatcherFiles.map(file => require(file));
const owners = problemMatchers.map(ms => ms.problemMatcher.map(m => m.owner)).flat();
if (action == "run" || action == "add") {
for (const file of problemMatcherFiles) {
core.debug(`Add matcher: ${file}`)
console.log(`::add-matcher::${file}`)
}
}
if (action == "run") {
try {
await exec.exec(run);
} catch (e) {
core.setFailed(e.message);
}
}
if (action == "run" || action == "remove") {
for (const owner of owners) {
core.debug(`Remove matcher: ${owner}`);
console.log(`::remove-matcher owner=${owner}::`);
}
}
}
main().catch(e => core.setFailed(e.message));