forked from JetBrains/ring-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
security-audit-ci.js
44 lines (39 loc) · 969 Bytes
/
security-audit-ci.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
const {execSync} = require('child_process');
const {writeFileSync} = require('fs');
const tsm = require('teamcity-service-messages');
// see https://docs.npmjs.com/cli/v8/commands/npm-audit#audit-level
const MIN_LEVEL = process.env.SEVERITY_LEVEL || 'high';
try {
execSync(`npm audit --production --audit-level ${MIN_LEVEL}`);
process.exit(0);
} catch (e) {
writeFileSync(
'npm-audit.html',
`
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<pre>
${e.stdout.toString().replace(/.\[\d+m/g, '')}
</pre>
</body>
</html>
`,
);
}
try {
execSync(`npm audit --production --audit-level ${MIN_LEVEL} --json`);
} catch (e) {
const {advisories} = JSON.parse(e.stdout.toString());
Object.values(advisories).
forEach(({id, severity, overview, recommendation, references}) =>
tsm.buildProblem({
identity: id,
description: `[${severity} severity] ${overview}.
${recommendation}
${references}`
})
);
}