Adding Golang code coverage badge in gitlab
Currently there is no example in gitlab official documentation regarding code coverage for golang.
However I found:
So I tried them out and it looks to work fine.
I quickly made a test repo: https://gitlab.com/emirot.nolan/go-test-coverage/ To try that out and it work fine !
Here is the gitlab-ci.yml
stages: - coveragetest test: stage: coveragetest image: golang script: - go get github.com/t-yuki/gocover-cobertura - go test ./... -v -coverprofile coverage.txt - gocover-cobertura < coverage.txt > coverage.xml coverage: /^coverage:\s(\d+(?:\.\d+)?%)/ artifacts: name: $CI_JOB_NAME/coverage.txt paths: - coverage.xml expire_in: 2 days reports: cobertura: coverage.xml
Then in order to get the coverage badge it can be added in the readme or in the repo settings>general>badges.
Or in the readme, for my repo like so: