Coverage hook.

This commit is contained in:
Nuno Cruces
2023-01-26 10:10:13 +00:00
parent a327cf5e08
commit 44854a7495
3 changed files with 1719 additions and 6 deletions

1707
.github/coverage.html vendored Normal file

File diff suppressed because it is too large Load Diff

16
.github/coverage.sh vendored
View File

@@ -1,15 +1,21 @@
#!/usr/bin/env bash
set -eo pipefail
cd -P -- "$(dirname -- "$0")"
SCRIPT_DIR="$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")"
go test ./... -coverprofile "$SCRIPT_DIR/coverage.out"
go tool cover -html="$SCRIPT_DIR/coverage.out" -o "$SCRIPT_DIR/coverage.html"
COVERAGE=$(go tool cover -func="$SCRIPT_DIR/coverage.out" | grep total: | grep -Eo '[0-9]+\.[0-9]+')
echo
echo "Full coverage: $COVERAGE% of statements"
go test ../... -coverprofile coverage.svg
COVERAGE=$(go tool cover -func=coverage.svg | grep total: | grep -Eo '[0-9]+\.[0-9]+')
echo $COVERAGE
COLOR=orange
if (( $(echo "$COVERAGE <= 50" | bc -l) )) ; then
COLOR=red
elif (( $(echo "$COVERAGE > 80" | bc -l) )); then
COLOR=green
fi
curl -s "https://img.shields.io/badge/coverage-$COVERAGE%25-$COLOR" > coverage.svg
curl -s "https://img.shields.io/badge/coverage-$COVERAGE%25-$COLOR" > "$SCRIPT_DIR/coverage.svg"
git add "$SCRIPT_DIR/coverage.html" "$SCRIPT_DIR/coverage.svg"