Last active
December 13, 2022 23:02
-
-
Save zerotacg/a131d73bf3f85c5e0309762ac8bbdf06 to your computer and use it in GitHub Desktop.
print coverage stats for usage in gitlab coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.xml.XmlParser | |
import java.text.DecimalFormat | |
tasks.register('koverStats') { | |
dependsOn ':koverXmlReport' | |
def percentageFormat = new DecimalFormat("#.##%") | |
ext.srcFile = new File(buildDir, 'reports/kover/xml/report.xml') | |
inputs.file srcFile | |
doLast { | |
println "Coverage Stats." | |
def report = new XmlParser().parse(srcFile) | |
report.counter.each { counter -> | |
def type = counter.@type | |
def missed = Integer.parseInt(counter.@missed) | |
def covered = Integer.parseInt(counter.@covered) | |
def total = missed + covered | |
def percentage = covered / total | |
println "Type: $type missed: $missed covered: $covered percentage: ${percentageFormat.format(percentage)}" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried to convert this to the Groovy, but had a fail. Maybe, will more simple to convert my .gradle file to gradle.kts. Thank you!