1
1
#! /bin/bash
2
2
3
- set -euo pipefail
3
+ set -eo pipefail
4
4
5
5
mkdir -p ./govulncheck 2> /dev/null
6
6
@@ -13,23 +13,36 @@ FAILED=0
13
13
# Repository prefix to remove from package names
14
14
REPO_PREFIX=$( go list -m)
15
15
16
+ # Use a bash regex to extract the the value of the --format flag
17
+ # from the GOVULN_OPTS environment variable
18
+ if [[ " $GOVULN_OPTS " =~ .* --format[[:space:]]+ ([a-z]+).* ]]; then
19
+ FORMAT=${BASH_REMATCH[1]}
20
+ fi
21
+
16
22
# Run govulncheck for each package
17
23
for pkg in $ALL_PKG_DIRS ; do
18
- # Remove the repository prefix from the package name to keep the category names short
19
- # and replace slashes with underscores to make clear that the categories are not nested.
20
- OUTPUT_FILE=" ./govulncheck/$( echo " $pkg " | sed " s|^$REPO_PREFIX /||" | tr ' /' ' _' ) .sarif"
21
- echo -e " \nRunning govulncheck for package $pkg "
22
- if ! govulncheck ${GOVULN_OPTS:- } " $pkg " > " $OUTPUT_FILE " ; then
23
- echo " govulncheck failed for package $pkg , output saved to $OUTPUT_FILE "
24
- FAILED=1
24
+ echo -e " \n**** Running govulncheck for package $pkg "
25
+ set +e
26
+ if [[ -z $FORMAT ]]; then
27
+ govulncheck ${GOVULN_OPTS} $pkg
25
28
else
26
- echo " govulncheck succeeded for package $pkg , output saved to $OUTPUT_FILE "
29
+ # Remove the repository prefix from the package name to keep the category names short
30
+ # and replace slashes with underscores to make clear that the categories are not nested.
31
+ OUTPUT_FILE=" ./govulncheck/$( echo " $pkg " | sed " s|^$REPO_PREFIX /||" | tr ' /' ' _' ) .$FORMAT "
32
+ govulncheck ${GOVULN_OPTS} $pkg > $OUTPUT_FILE
33
+ fi
34
+ if [ $? -eq 0 ]; then
35
+ echo -e " \n**** govulncheck succeeded for package $pkg "
36
+ else
37
+ echo -e " \n**** govulncheck failed for package $pkg "
38
+ FAILED=1
27
39
fi
40
+ set -e
28
41
done
29
42
30
43
if [ $FAILED -ne 0 ]; then
31
- echo -e " \ngovulncheck failed for one or more packages"
44
+ echo -e " \n**** govulncheck failed for one or more packages"
32
45
exit 1
33
46
fi
34
47
35
- echo -e " \ngovulncheck completed successfully for all packages"
48
+ echo -e " \n**** govulncheck completed successfully for all packages"
0 commit comments