Bump checkstyle version
[dcaegen2/collectors/hv-ves.git] / build / hv-collector-coverage / check-coverage.sh
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 JACOCO_REPORT="$1"
5 MIN_COVERAGE_PERCENT="$2"
6 LOG_FILE=target/check-coverage.log
7
8 function coverage_from_report() {
9   local xpath_expr="string(/report/counter[@type='INSTRUCTION']/@$1)"
10   xpath -q -e "$xpath_expr" "$JACOCO_REPORT" 2>> ${LOG_FILE}
11 }
12
13 missed=$(coverage_from_report missed)
14 covered=$(coverage_from_report covered)
15 total=$(($missed + $covered))
16 coverage=$((100 * $covered / $total))
17
18 if [[ $(wc -c < ${LOG_FILE}) > 0 ]]; then
19   echo "Warnings from xpath evaluation:"
20   cat ${LOG_FILE}
21   echo
22 fi
23
24 echo "Coverage: $coverage% (covered/total: $covered/$total)"
25
26 if [[ ${coverage} -lt ${MIN_COVERAGE_PERCENT} ]]; then
27   echo "Coverage is too low. Minimum coverage: $MIN_COVERAGE_PERCENT%"
28   exit 1
29 fi
30