From 70cc564c8fb7213cd928ccc1d75b50225d55d202 Mon Sep 17 00:00:00 2001 From: Jeff Quast Date: Mon, 24 Nov 2014 17:08:54 -0800 Subject: Allow teamcity to track coverage for builds We'll still use coveralls.io, though! This just makes it so that TeamCity is aware of change of code coverage when viewing build results. --- tools/teamcity-coverage-report.sh | 27 +++++++++++++++++++++++++++ tools/teamcity-runtests.sh | 7 ++++--- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100755 tools/teamcity-coverage-report.sh diff --git a/tools/teamcity-coverage-report.sh b/tools/teamcity-coverage-report.sh new file mode 100755 index 0000000..5610202 --- /dev/null +++ b/tools/teamcity-coverage-report.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# This is to be executed by each individual OS test. It only +# combines coverage files and reports locally to the given +# TeamCity build configuration. +set -e +set -o pipefail +[ -z ${TEMP} ] && TEMP=/tmp + +# combine all .coverage* files, +coverage combine + +# create ascii report, +report_file=$(mktemp $TEMP/coverage.XXXXX) +coverage report --rcfile=`dirname $0`/../.coveragerc > "${report_file}" 2>/dev/null + +# Report Code Coverage for TeamCity, using 'Service Messages', +# https://confluence.jetbrains.com/display/TCD8/How+To...#HowTo...-ImportcoverageresultsinTeamCity +# https://confluence.jetbrains.com/display/TCD8/Custom+Chart#CustomChart-DefaultStatisticsValuesProvidedbyTeamCity +total_no_lines=$(awk '/TOTAL/{print $2}') +total_no_misses=$(awk '/TOTAL/{print $3}') +total_no_covered=$((${total_no_lines} - ${total_no_misses})) +echo "##teamcity[buildStatisticValue key='' value='<${total_no_lines}>']" +echo "##teamcity[buildStatisticValue key='' value='<${total_no_covered}>']" + +# Display for human consumption and remove ascii file. +cat "${report_file}" +rm "${report_file}" diff --git a/tools/teamcity-runtests.sh b/tools/teamcity-runtests.sh index 48d3db9..a61d979 100755 --- a/tools/teamcity-runtests.sh +++ b/tools/teamcity-runtests.sh @@ -49,8 +49,9 @@ if [ $ret -ne 0 ]; then echo "the build should detect and report these failing tests." >&2 fi -# combine all coverage to single file, publish as build -# artifact in {pexpect_projdir}/build-output +# combine all coverage to single file, report for this build, +# then move into ./build-output/ as a unique artifact to allow +# the final "Full build" step to combine and report to coveralls.io +`dirname $0`/teamcity-coverage-report.sh mkdir -p build-output -coverage combine mv .coverage build-output/.coverage.${osrel}.py{$pyversion}.$RANDOM.$$ -- cgit v1.2.1