ci: move coverage validation to separate script for better readability
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
0e150f0ba9
commit
2e267ac6dd
|
|
@ -10,6 +10,7 @@ steps:
|
||||||
- go vet ./...
|
- go vet ./...
|
||||||
- mkdir -p .build
|
- mkdir -p .build
|
||||||
- go test -v -coverprofile .build/coverage.out ./...
|
- go test -v -coverprofile .build/coverage.out ./...
|
||||||
- go tool cover -func .build/coverage.out | tee .build/coverage.txt | awk '/^total:/ { gsub("%", "", $3); if ($3 + 0 < 80) { printf("Coverage %.1f%% is below 80%%\n", $3); exit 1 } }'
|
- go tool cover -func .build/coverage.out | tee .build/coverage.txt
|
||||||
|
- bash scripts/check-coverage.sh .build/coverage.out 80
|
||||||
- go install golang.org/x/vuln/cmd/govulncheck@latest
|
- go install golang.org/x/vuln/cmd/govulncheck@latest
|
||||||
- govulncheck -json ./... > vulncheck.json
|
- govulncheck -json ./... > vulncheck.json
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Check test coverage against minimum threshold
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
COVERAGE_FILE="${1:-.build/coverage.out}"
|
||||||
|
MIN_COVERAGE="${2:-80}"
|
||||||
|
|
||||||
|
if [ ! -f "$COVERAGE_FILE" ]; then
|
||||||
|
echo "Error: Coverage file not found: $COVERAGE_FILE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract coverage percentage using awk
|
||||||
|
COVERAGE=$(go tool cover -func "$COVERAGE_FILE" | awk '/^total:/ { match($0, /[0-9.]+%/); print substr($0, RSTART, RLENGTH-1) }')
|
||||||
|
|
||||||
|
echo "Total coverage: ${COVERAGE}%"
|
||||||
|
|
||||||
|
# Compare as integers (remove decimals for simpler comparison)
|
||||||
|
COVERAGE_INT=${COVERAGE%.*}
|
||||||
|
|
||||||
|
if [ "$COVERAGE_INT" -lt "$MIN_COVERAGE" ]; then
|
||||||
|
echo "Coverage ${COVERAGE}% is below minimum ${MIN_COVERAGE}%"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Coverage check passed"
|
||||||
|
exit 0
|
||||||
Loading…
Reference in New Issue