vmware-go-kcl-v2/support/scripts/check.sh
Fabiano Arruda 7af9290557 Upgrade golang 1.17 (#98)
* upgrade to golang 1.17

Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>

# Conflicts:
#	go.mod
#	go.sum

* improve after shell lint

Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>

* improve after upgrade docker image (used by the build system)

Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>

* remove not needed variable

Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>

* apply fixes after security scan (hmake test)

Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>

* add missing package after merge with latest master branch code.

Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>

* improve docker layer

Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>

* upgrade packages

Signed-off-by: Fabiano Graças <fabiano.gracas@faro.com>

Co-authored-by: Fabiano Graças <fabiano.gracas@faro.com>
2021-12-20 21:21:15 -06:00

75 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
. support/scripts/functions.sh
checkfmt() {
local files="$(gofmt -l $(local_go_pkgs))"
if [ -n "$files" ]; then
echo "You need to run \"gofmt -w ./\" to fix your formating."
echo "$files" >&2
return 1
fi
}
lint() {
golangci-lint run \
--skip-files=_mock.go \
--disable=golint \
--skip-dirs=test \
--fast \
--timeout=600s \
--verbose \
$(local_go_pkgs)
}
scanast() {
set +e
gosec version
gosec ./... > security.log 2>&1
set -e
local issues="$(grep -E 'Severity: MEDIUM' security.log | wc -l)"
if [ -n $issues ] && [ $issues -gt 0 ]; then
echo ""
echo "Medium Severity Issues:"
grep -E "Severity: MEDIUM" -A 1 security.log
echo $issues "medium severity issues found."
fi
local issues="$(grep -E 'Severity: HIGH' security.log | grep -v vendor)"
local issues_count="$(grep -E 'Severity: HIGH' security.log | grep -v vendor | wc -l)"
if [ -n $issues_count ] && [ $issues_count -gt 0 ]; then
echo ""
echo "High Severity Issues:"
grep -E "Severity: HIGH" -A 1 security.log
echo $issues_count "high severity issues found."
echo $issues
echo "You need to resolve the high severity issues at the least."
exit 1
fi
local issues="$(grep -E 'Errors unhandled' security.log | grep -v vendor | grep -v /src/go/src)"
local issues_count="$(grep -E 'Errors unhandled' security.log | grep -v vendor | grep -v /src/go/src | wc -l)"
if [ -n $issues_count ] && [ $issues_count -gt 0 ]; then
echo ""
echo "Unhandled errors:"
grep -E "Errors unhandled" security.log
echo $issues_count "unhandled errors, please indicate with the right comment that this case is ok, or handle the error."
echo $issues
echo "You need to resolve the all unhandled errors."
exit 1
fi
rm security.log
}
usage() {
echo "check.sh fmt|lint" >&2
exit 2
}
case "$1" in
fmt) checkfmt ;;
lint) lint ;;
scanast) scanast;;
*) usage ;;
esac