A Go utility that reports the total code coverage from a cobertura XML code coverage report.
This is useful in cases like the gitlab pipelines that take a regular expression and uses the last match found from the output to find the coverage. For go test --cover this becomes an issue if you have multiple packages as only the last packages coverage will be reported on.
This utility will read the generated cobertura report and output the total coverage. If this utility is run at the end of the gitlab job, then the regex can match on the total code coverage.
An example .gitlab-ci.yml job might look something like the following:
golang:
stage: test
script:
- go install gotest.tools/gotestsum
- go install github.com/boumenot/gocover-cobertura
- go install github.com/ggere/gototal-cobertura
- gotestsum --junitfile report.xml --format testname -- -coverprofile=coverage.out ./...
- gocover-cobertura < coverage.out > coverage.xml
- gototal-cobertura < coverage.xml
coverage: "/coverage: \d+.\d+% of statements/"
artifacts:
when: always
reports:
junit: report.xml
cobertura: coverage.xmlTotal coverage: 62.50% of statementsgo install gitlab.com/ggere/gototal-cobertura@latest