0

Based on this question on StackOverflow, I added test coverage into my Gitlab CI/CD YAML file, and I expect the result gets uploaded into codeclimate.

- go get github.com/axw/gocov/gocov
- export CC_TEST_REPORTER_ID=My_REPO_ID
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
- gocov test -v ./... -coverprofile=out
- ./cc-test-reporter format-coverage --input-type gocov out
- ./cc-test-reporter upload-coverage

The script runs test successfully in all my packages, and the output of CI/CD shows that all tests in different packages ran, but uploaded report into codeclimate only shows there is only one file with test-coverage and that is the last test package, instead of showing all.

code-climate result report page

Mazdak
  • 771
  • 2
  • 11
  • 24

1 Answers1

0

I mixed the solution with another answer in the same stackoverflow link and finally create a bash file and ran it from my yaml file like this so the report output contain all package reports, this is my script:

go get github.com/axw/gocov/gocov
export CC_TEST_REPORTER_ID=My_ID
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build

for pkg in $(go list ./... | grep -v vendor); do
    go test -coverprofile=$(echo $pkg | tr / -).cover $pkg
done
echo "mode: set" > c.out
grep -h -v "^mode:" ./*.cover >> c.out
rm -f *.cover

./cc-test-reporter after-build
Mazdak
  • 771
  • 2
  • 11
  • 24