-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
90 lines (85 loc) · 2.74 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import core from '@actions/core';
import webExt from 'web-ext';
import qs from 'node:querystring';
import path from 'node:path';
const NONE = 0,
FIRST = 1,
source = core.getInput('extension-root') || '.',
privileged = core.getBooleanInput('privileged') || false,
selfHosted = core.getBooleanInput('self-hosted') || false;
//TODO support explicit config path?
function report(level, info, message) {
const meta = qs.stringify(info, ',', '=', {
encodeURIComponent: (string) => string,
});
core.info(`::${level} ${meta}::${message}`);
}
function formatLocation(lintReport) {
return [
lintReport.file,
lintReport.line,
lintReport.column,
].filter((exists) => !!exists)
.join(':');
}
function formatMessage(lintReport) {
const verbose = /true/.test(core.getInput('verbose'));
if(verbose) {
return `${lintReport.message} - ${lintReport.description}`;
}
return lintReport.message;
}
webExt.cmd.lint({
sourceDir: source,
output: 'none',
privileged,
selfHosted,
},
{
shouldExitProgram: false,
})
.then((lintResult) => {
if(lintResult.errors.length > NONE) {
core.startGroup('Errors');
for(const error of lintResult.errors) {
if(error.file) {
report('error', {
file: path.join(source, error.file),
line: error.line || FIRST,
col: error.column || FIRST,
}, formatMessage(error));
}
else {
core.error(formatMessage(error));
}
}
core.endGroup();
}
if(lintResult.warnings.length) {
core.startGroup('Warnings');
for(const warning of lintResult.warnings) {
if(warning.file) {
report('warning', {
file: path.join(source, warning.file),
line: warning.line || FIRST,
col: warning.column || FIRST,
}, formatMessage(warning));
}
else {
core.warning(formatMessage(warning));
}
}
core.endGroup();
}
if(lintResult.notices.length) {
core.startGroup('Notices');
for(const notice of lintResult.notices) {
core.info(`${formatLocation(notice)} ${formatMessage(notice)}`);
}
core.endGroup();
}
if(lintResult.summary.errors > NONE) {
core.setFailed(`${lintResult.summary.errors} error(s) were reported by web-ext`);
}
})
.catch((error) => core.setFailed(error.message));