github.com/koko1123/flow-go-1@v0.29.6/cover-summary.sh (about) 1 #!/bin/bash 2 3 ### 4 # This file generates a set of STDOUT outputs that teamcity picks up and charts as statistics. 5 # It takes the output of `gocov test` or `gocov convert` (e.g. gocov's JSON interchange format) and prints out a summary 6 ### 7 8 9 # Add all the sub coverages to the cover file 10 tail -n +2 crypto/$COVER_PROFILE >> $COVER_PROFILE 11 gocov convert $COVER_PROFILE > cover.json 12 13 # The summary lines are indicated by a long running set of `-`s, therefore to get the summary lines, we grep the lines with a set of dashes 14 # To remove noise, we remove the root project path `github.com/onflow/flow-go` and all the dashes using `sed` 15 # Then we print out the lines in a way that teamcity understands, e.g. `##teamcity[buildStatisticValue key='package' value='100.00]'` 16 gocov report cover.json | grep -e '--------' | sed -e "s/^github.com\/onflow\/flow-go\///" -e "s/-//g" > cover-summary 17 while read line; do 18 tcLine="##teamcity[buildStatisticValue" 19 eval 'arr=($line)' 20 key=${arr[0]} 21 val=${arr[1]%\%} 22 tcLine="$tcLine key='coverage-$key' value='$val']" 23 echo $tcLine 24 done <cover-summary 25 26 # Also, we can make use of the total repo coverage as well. Done by `grep`ing the `Total Coverage` line. 27 # Team city has specific keys for this coverage, e.g. CodeCoverageAbsLCovered and CodeCoverageAbsLTotal 28 eval 'totalArr=($(gocov report cover.json | grep -e "Total Coverage:"))' 29 total=${totalArr[3]} 30 eval 'lines=($(echo $total | tr "/" " "))' 31 echo "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='${lines[0]#(}']" 32 echo "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='${lines[1]%)}']"