-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.sh
executable file
·74 lines (60 loc) · 1.7 KB
/
script.sh
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
#!/bin/bash -l
#
# license-compliance
# https://github.com/mikaelvesavuori/license-compliance-action
#
# This is a wrapper on top of `license-compliance`
# (https://www.npmjs.com/package/license-compliance)
# to help check licenses of production dependencies during CI.
#
set -o pipefail
# Set user inputs
LICENSES="$1"
echo "LICENSES is: $LICENSES"
NESTED_FIELD="$2"
echo "NESTED_FIELD is: $NESTED_FIELD"
EXCLUDE_PATTERN="$3"
echo "EXCLUDE_PATTERN is: $EXCLUDE_PATTERN"
# This value will contain the final license string
LICENSE_STRING="$LICENSES"
main() {
if [ -f "package.json" ]; then
installNodeDependencies
getLicenseStringFromUrl
runLicenseComplianceSummary
runLicenseCompliance
fi
}
installNodeDependencies() {
echo "Installing dependencies...\n"
npm install license-compliance -D
}
getLicenseStringFromUrl() {
# Thanks to contributors at https://stackoverflow.com/questions/3183444/check-for-valid-link-url for ideas.
REGEX='(https)://'
if [[ $LICENSES =~ $REGEX ]]; then
echo "Getting license string from provided URL: $LICENSES"
LICENSE_RESPONSE=$(curl -X GET "$LICENSES" --silent)
if [[ $NESTED_FIELD ]]; then
LICENSE_STRING=$(echo "$LICENSE_RESPONSE" | jq ".$NESTED_FIELD" -r)
echo "Licenses picked up: $LICENSE_STRING"
else
LICENSE_STRING=$(echo "$LICENSE_RESPONSE" | jq "." -r)
fi
fi
}
runLicenseComplianceSummary() {
echo "Summary of all licenses:"
npx license-compliance
}
runLicenseCompliance() {
echo "Checking compliance:"
npx license-compliance --production --allow "$LICENSE_STRING" --exclude "$EXCLUDE_PATTERN"
echo ""
echo "License scan complete!"
echo ""
EXIT_CODE=$(echo $?)
exit $EXIT_CODE
}
main "$@"
exit