Commit 72731282 authored by Nick Gaskill's avatar Nick Gaskill

Merge branch 'update-instructions-for-go-tool-cover' into 'master'

Remove reference to unmaintained go tool

See merge request gitlab-org/gitlab!84433
parents 654635f3 112e7f3a
...@@ -326,18 +326,13 @@ run tests: ...@@ -326,18 +326,13 @@ run tests:
The following [`.gitlab-ci.yml`](../../../ci/yaml/index.md) example for Go uses: The following [`.gitlab-ci.yml`](../../../ci/yaml/index.md) example for Go uses:
- [`go test`](https://go.dev/doc/tutorial/add-a-test) to run tests. - [`go test`](https://go.dev/doc/tutorial/add-a-test) to run tests.
- [`gocover-cobertura`](https://github.com/t-yuki/gocover-cobertura) to convert Go's coverage profile into the Cobertura XML format. - [`gocover-cobertura`](https://github.com/boumenot/gocover-cobertura) to convert Go's coverage profile into the Cobertura XML format.
This example assumes that [Go modules](https://go.dev/ref/mod) are being used. This example assumes that [Go modules](https://go.dev/ref/mod)
Using Go modules causes paths within the coverage profile to be prefixed with your are being used. Please note that the `-covermode count` option does not work with the `-race` flag.
project's module identifier, which can be found in the `go.mod` file. This If you want to generate code coverage while also using the `-race` flag, you must switch to
prefix must be removed for GitLab to parse the Cobertura XML file correctly. You can use the following `sed` command to remove the prefix: `-covermode atomic` which is slower than `-covermode count`. See [this blog post](https://go.dev/blog/cover)
for more details.
```shell
sed -i 's;filename=\"<YOUR_MODULE_ID>/;filename=\";g' coverage.xml
```
Replace the `gitlab.com/my-group/my-project` placeholder in the following example with your own module identifier to make it work.
```yaml ```yaml
run tests: run tests:
...@@ -345,9 +340,9 @@ run tests: ...@@ -345,9 +340,9 @@ run tests:
image: golang:1.17 image: golang:1.17
script: script:
- go install - go install
- go test . -coverprofile=coverage.txt -covermode count - go test ./... -coverprofile=coverage.txt -covermode count
- go run github.com/t-yuki/gocover-cobertura < coverage.txt > coverage.xml - go get github.com/boumenot/gocover-cobertura
- sed -i 's;filename=\"gitlab.com/my-group/my-project/;filename=\";g' coverage.xml - go run github.com/boumenot/gocover-cobertura < coverage.txt > coverage.xml
artifacts: artifacts:
reports: reports:
cobertura: coverage.xml cobertura: coverage.xml
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment