ci: Generate Cobertura XML and use it to feed gitlab for MR integration

gitlab has coverage integration in MRs, but we need a cobertura
formatted XML files (each must be less than 10 MB [1]) to show it, so
generate it using a python script and inform gitlab about it.

See https://docs.gitlab.com/ee/ci/testing/test_coverage_visualization.html

[1] https://gitlab.com/gitlab-org/gitlab/-/issues/328772#note_840831654
This commit is contained in:
Marco Trevisan (Treviño) 2022-07-21 01:05:42 +02:00
parent 29cf6b2b65
commit 3ddfb10b0b
2 changed files with 13 additions and 1 deletions

View File

@ -10,7 +10,7 @@ cache:
- _ccache/ - _ccache/
variables: variables:
FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/glib/fedora:v18" FEDORA_IMAGE: "registry.gitlab.gnome.org/gnome/glib/fedora:v19"
COVERITY_IMAGE: "registry.gitlab.gnome.org/gnome/glib/coverity:v7" COVERITY_IMAGE: "registry.gitlab.gnome.org/gnome/glib/coverity:v7"
DEBIAN_IMAGE: "registry.gitlab.gnome.org/gnome/glib/debian-stable:v13" DEBIAN_IMAGE: "registry.gitlab.gnome.org/gnome/glib/debian-stable:v13"
MINGW_IMAGE: "registry.gitlab.gnome.org/gnome/glib/mingw:v9" MINGW_IMAGE: "registry.gitlab.gnome.org/gnome/glib/mingw:v9"
@ -482,6 +482,10 @@ coverage:
paths: paths:
- _coverage/coverage/index.html - _coverage/coverage/index.html
- _coverage - _coverage
reports:
coverage_report:
coverage_format: cobertura
path: _coverage/*-cobertura/cobertura-*.xml
before_script: before_script:
- bash .gitlab-ci/show-execution-environment.sh - bash .gitlab-ci/show-execution-environment.sh
script: script:

View File

@ -10,6 +10,14 @@ for path in _coverage/*.lcov; do
lcov --config-file .lcovrc -r "${path}" '*/_build/*' -o "$(pwd)/${path}" lcov --config-file .lcovrc -r "${path}" '*/_build/*' -o "$(pwd)/${path}"
# Remove any coverage from system files # Remove any coverage from system files
lcov --config-file .lcovrc -e "${path}" "$(pwd)/*" -o "$(pwd)/${path}" lcov --config-file .lcovrc -e "${path}" "$(pwd)/*" -o "$(pwd)/${path}"
# Convert to cobertura format for gitlab integration
cobertura_base="${path/.lcov}-cobertura"
cobertura_xml="${cobertura_base}.xml"
lcov_cobertura "${path}" --output "${cobertura_xml}"
mkdir -p "${cobertura_base}"
cobertura-split-by-package.py "${cobertura_xml}" "${cobertura_base}"
rm -f "${cobertura_xml}"
done done
genhtml \ genhtml \