Extract code coverage summary to its own script

This commit is contained in:
Mislav Marohnić 2018-06-09 18:10:52 +02:00
Родитель aecae7c2b5
Коммит f650a22525
2 изменённых файлов: 24 добавлений и 18 удалений

Просмотреть файл

@ -45,9 +45,29 @@ generate() {
awk '/^total:/ { print $(NF) }' "${HUB_COVERAGE%.out}.func"
}
case "${1?}" in
prepare | generate )
"$1"
summarize() {
local total_coverage
local min_coverage="${1?}"
total_coverage="$(generate)"
echo "Code coverage: $total_coverage"
local result="$(bc <<<"${total_coverage%\%} < $min_coverage")"
if [ "$result" -eq 1 ]; then
echo "Error: coverage dropped below the minimum treshold of ${min_coverage}%!"
if [ -n "$CI" ]; then
html_result="${HUB_COVERAGE%.out}.html"
html_result="${html_result#$PWD/}"
printf 'Please run `script/test --coverage` locally and open `%s` to analyze the results.\n' "$html_result"
fi
return 1
fi
}
cmd="${1?}"
shift 1
case "$cmd" in
prepare | generate | summarize )
"$cmd" "$@"
;;
* )
exit 1

Просмотреть файл

@ -35,21 +35,7 @@ trap "exit 1" INT
script/build
go test ./... || STATUS="$?"
script/ruby-test "$@" || STATUS="$?"
if [ -n "$HUB_COVERAGE" ]; then
total_coverage="$(script/coverage generate)"
echo "Code coverage: $total_coverage"
result="$(bc <<<"${total_coverage%\%} < $min_coverage")"
if [ "$result" -eq 1 ]; then
echo "Error: coverage dropped below the minimum treshold of ${min_coverage}%!"
if [ -n "$CI" ]; then
html_result="${HUB_COVERAGE%.out}.html"
html_result="${html_result#$PWD/}"
printf 'Please run `script/test --coverage` locally and open `%s` to analyze the results.\n' "$html_result"
fi
STATUS=1
fi
fi
[ -z "$HUB_COVERAGE" ] || script/coverage summarize "$min_coverage" || STATUS=1
if [ -n "$CI" ]; then
make fmt >/dev/null