-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
45 lines (41 loc) · 1.27 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
const core = require('@actions/core')
const licenseChecker = require('license-checker')
const getMultilineInput = (name) => core.getInput(name).split('\n');
const checkLicenses = (path) => {
return new Promise((resolve) => {
const allowedLicenses = getMultilineInput('allow-only')
const excludePackages = getMultilineInput('exclude-packages')
try {
licenseChecker.init({
start: path,
onlyAllow: allowedLicenses.join(';'),
excludePackages: excludePackages.join(';'),
excludePrivatePackages: Boolean(core.getInput('exclude-private-packages'))
}, err => {
resolve(err);
})
} catch (error) {
resolve(error);
}
});
}
try {
const paths = getMultilineInput('paths');
Promise.all(paths.map(checkLicenses)).then((pathsErrors) => {
if (pathsErrors.filter(Boolean).length) {
pathsErrors.forEach((pathCheckErrors, index) => {
if (pathCheckErrors) {
console.log(`Found errors while check path "${paths[index]}"`);
console.log(pathCheckErrors);
}
})
core.setFailed('Licenses check has been failed')
} else {
console.log('Success')
}
}).catch((error) => {
core.setFailed(error.message)
})
} catch (error) {
core.setFailed(error.message)
}