Files
donotpassgo/src/security.sh

42 lines
1.0 KiB
Bash
Raw Normal View History

2026-04-03 00:22:36 -04:00
#!/bin/bash
set -eo pipefail
if [[ "$STATIC_FLAG" == "no" && "$VULN_CHECK" == "no" ]]; then
2026-04-03 00:22:36 -04:00
echo "[INFO] no security flags set, skipping!";
exit 0;
fi
2026-04-03 15:54:51 -04:00
toolchain=$(go mod edit -json go.mod | jq -r ".Toolchain // empty");
version=$(go env -json | jq -r ".GOVERSION // empty");
2026-04-03 15:28:01 -04:00
if [[ -n "$toolchain" ]]; then
2026-04-03 15:41:13 -04:00
echo "[DEBUG] overwriting version with toolchain";
2026-04-03 15:11:33 -04:00
version=$toolchain;
fi
if [[ "$STATIC_FLAG" == "yes" ]]; then
2026-04-03 15:11:33 -04:00
if GOTOOLCHAIN=$version gosec ./...; then
2026-04-03 00:22:36 -04:00
echo "[INFO] gosec passed!";
else
if [[ "$STATIC_FAIL" == "yes" ]]; then
2026-04-03 00:22:36 -04:00
echo "[FATAL] gosec failed!";
exit 1;
else
echo "[INFO] gosec failed!";
fi
fi
fi
2026-04-03 15:41:13 -04:00
if [ "$VULN_CHECK" == "yes" ]; then
2026-04-03 15:11:33 -04:00
if GOTOOLCHAIN=$version govulncheck ./...; then
2026-04-03 00:22:36 -04:00
echo "[INFO] govulncheck passed!";
else
2026-04-03 15:41:13 -04:00
if [ "$VULN_FAIL" == "yes" ]; then
2026-04-03 00:22:36 -04:00
echo "[FATAL] govulncheck failed!"
exit 1;
else
echo "[INFO] govulncheck failed!"
fi
fi
fi