Skip to content

Commit b523488

Browse files
committed
join uncovered lines and sort input before processing
1 parent 7b63f45 commit b523488

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

coverage_summary.awk

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ BEGIN {
2020
file = ""
2121
}
2222
$1 !~ /mode:/ {
23-
if (match($1,"^"package"([^:]+):([0-9]+).[0-9]+,([0-9]+).[0-9]+",f)) {
23+
if (match($1,"^"package"(.+)$",f)) {
2424
if (file != "" && file != f[1] ) {
25+
# write file entry with coverage and uncovered lines
2526
fileCoverage = fileCovered/fileStatements*100
2627
if (lineStart != "" && lineEnd != "") {
28+
if (uncoveredLines != "") {
29+
uncoveredLines = uncoveredLines", "
30+
}
2731
uncoveredLines = sprintf("%s[%s-%s](%s%s#L%s-L%s)", uncoveredLines, lineStart, lineEnd, baseUrl, file, lineStart, lineEnd)
2832
}
2933
details = sprintf("%s|%s %.1f%|%s|%s|\n", details, bar(fileCoverage), fileCoverage, file, uncoveredLines)
@@ -32,27 +36,32 @@ $1 !~ /mode:/ {
3236
uncoveredLines = ""
3337
lineStart = ""
3438
lineEnd = ""
35-
}
39+
}
40+
# start new file coverage measuring
3641
file = f[1]
37-
statements += $2
38-
fileStatements += $2
39-
if ($3 != "0") {
40-
covered += $2
41-
fileCovered += $2
42+
statements += $4
43+
fileStatements += $4
44+
if ($5 != "0") {
45+
# covered lines
46+
covered += $4
47+
fileCovered += $4
48+
49+
if (lineStart != "" && lineEnd != "") {
50+
if (uncoveredLines != "") {
51+
uncoveredLines = uncoveredLines", "
52+
}
53+
uncoveredLines = sprintf("%s[%s-%s](%s%s#L%s-L%s)", uncoveredLines, lineStart, lineEnd, baseUrl, file, lineStart, lineEnd)
54+
lineStart = ""
55+
lineEnd = ""
56+
}
57+
4258
next
4359
}
44-
if (lineStart == "" && lineEnd == "") {
45-
lineStart = f[2]
46-
lineEnd = f[3]
47-
next
60+
# not covered lines
61+
if (lineStart == "") {
62+
lineStart = $2
4863
}
49-
if (lineEnd+0 == f[2]+0 || lineEnd+1 == f[2]+0) {
50-
lineEnd = f[3]
51-
next
52-
}
53-
uncoveredLines = sprintf("%s[%s-%s](%s%s#L%s-L%s), ", uncoveredLines, lineStart, lineEnd, baseUrl, file, lineStart, lineEnd)
54-
lineStart = f[2]
55-
lineEnd = f[3]
64+
lineEnd = $3
5665
}
5766
}
5867
END {

summary.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fi
1414
if [[ -f "$GITHUB_WORKSPACE/$COVERAGE_PROFILE" ]] ; then
1515
echo "process coverage profile"
1616
PACKAGE=$(awk '$1 ~ /module/ { print $2 }' $GITHUB_WORKSPACE/go.mod)
17-
awk -f $SCRIPT_DIR/coverage_summary.awk -v package="$PACKAGE" -v baseUrl="$BASE_URL" $GITHUB_WORKSPACE/$COVERAGE_PROFILE >> $SUMMARY_FILE
17+
awk '{ gsub(/(\.[0-9]+,|\.[0-9]+ |:)/," "); print }' $GITHUB_WORKSPACE/$COVERAGE_PROFILE | sort -k1,1 -k2,2n | awk -f $SCRIPT_DIR/coverage_summary.awk -v package="$PACKAGE" -v baseUrl="$BASE_URL" >> $SUMMARY_FILE
1818
fi
1919

2020
if [[ "$WITH_ARCHIVE" == "true" && -f "$GITHUB_WORKSPACE/$COVERAGE_PROFILE" ]] ; then

0 commit comments

Comments
 (0)