diff options
author | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-23 14:45:39 +0200 |
---|---|---|
committer | Piotr Jaszczyk <piotr.jaszczyk@nokia.com> | 2018-08-27 14:53:20 +0200 |
commit | 851d47037b1092d4c2991289eef3bddb4439bd7a (patch) | |
tree | af8e5919f74f75a7321c43910a77bfffea89af41 /hv-collector-coverage/check-coverage.sh | |
parent | 1d9f81b69b5caad88373d3fcece4654df4729161 (diff) |
Fail build when coverage is too low
Minimum coverage set to 60%. It works by parsing aggregated Jacoco
report as oposed to jacoco:check goal which checks coverage at most
on submodule level.
Change-Id: Ie6f50ce9b2f15e62ad84480611897a98321a7af2
Issue-ID: DCAEGEN2-681
Signed-off-by: Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
Diffstat (limited to 'hv-collector-coverage/check-coverage.sh')
-rwxr-xr-x | hv-collector-coverage/check-coverage.sh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/hv-collector-coverage/check-coverage.sh b/hv-collector-coverage/check-coverage.sh new file mode 100755 index 00000000..7a2f4c6c --- /dev/null +++ b/hv-collector-coverage/check-coverage.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail + +JACOCO_REPORT="$1" +MIN_COVERAGE_PERCENT="$2" + +function coverage_from_report() { + local xpath_expr="string(/report/counter[@type='INSTRUCTION']/@$1)" + xpath -q -e "$xpath_expr" "$JACOCO_REPORT" +} + +missed=`coverage_from_report missed` +covered=`coverage_from_report covered` +total=$(($missed + $covered)) +coverage=$((100 * $covered / $total)) + +echo "Coverage: $coverage% (covered/total: $covered/$total)" + +if [[ $coverage -lt $MIN_COVERAGE_PERCENT ]]; then + echo "Coverage is too low. Minimum coverage: $MIN_COVERAGE_PERCENT%" + exit 1 +fi + |