-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display Coverage % in Gitlab #155
Comments
In the script tag block of your job (Inside .gitlab-ci.yml) you can add one line after executing kover: Then you can add the regex in a coverage tagcoverage tag for the same job. |
Until Kover provides an easy integration, here is particularly fragile way of doing this: values=$(cat build/reports/kover/project-xml/report.xml | tail -7 | head -5 | grep 'INSTRUCTION' | cut -d ' ' -f 3,4 | sed 's/missed="//;s/" covered="/ /;s/"\/>//')
missed=$(<<<$values cut -d ' ' -f 1)
covered=$(<<<$values cut -d ' ' -f 2)
echo "Coverage $(($covered * 100 / ($covered + $missed)))%" A simple way for Kover to make all of this unnecessary would be to provide a Gradle task similar to this: $ ./gradlew koverStats
Instruction: 12%
Branch: 32%
Line: 15%
Method: 35%
Class: 80% This command would also be useful for CLI users. |
I liked the idea of CLOVIS-AI and integrated it as a gradle task Still a bit hacky gradle task, maybe someone could improve on that After that I'm using this gitlab coverage config |
In case anyone interested in a Kotlin version of gradle task above(#229) tasks.register("koverPrintMergedXmlCoverage") {
val koverMergedXmlReport = tasks.named("koverMergedXmlReport")
dependsOn(koverMergedXmlReport)
doLast {
//language=RegExp
val regexp = """<counter type="INSTRUCTION" missed="(\d+)" covered="(\d+)"/>""".toRegex()
koverMergedXmlReport.get().outputs.files.forEach { file ->
// Read file by lines
file.useLines { lines ->
// Last line in file that matches regexp is the total coverage
lines.last(regexp::containsMatchIn).let { line ->
// Found the match
regexp.find(line)?.let {
val missed = it.groupValues[1].toInt()
val covered = it.groupValues[2].toInt()
println("Total Code Coverage: ${covered * 100 / (missed + covered)}%")
}
}
}
}
}
} |
Duplicates #229 |
Hello
I want to display the % of coverage in Gitlab.
I can get it by
grep -Eo "[0-9]+([.][0-9]+)%" path/to/report//index.html | head -1
But I don't know to display it in Gitlab as Coverage must be regular expression.
Thanks
The text was updated successfully, but these errors were encountered: