Search code examples
gocontinuous-integrationcode-coveragecode-climate

Codeclimate test coverage formatter for Golang


Nowhere in Codeclimate docs written how to specify coverage formatter. But when I'm trying to send coverage to Codeclimate:

./cc-test-reporter before-build
./cc-test-reporter after-build

It is failing:

Error: could not find any viable formatter. available formatters: simplecov, lcov, coverage.py, clover, gocov, gcov, cobertura, jacoco

I have gocov installed. Also I generated a report with goconv:

gocov test -coverprofile=out

And I tried to specify the report file to Codeclimate in various ways:

./cc-test-reporter after-build out
./cc-test-reporter after-build < out

But had no luck...

I haven't found any formatter related directives for .codeclimate.yml file. The doc is written in super "you know" style so it didn't help. How to enable/send test coverage with Codeclimate?


Solution

  • Export var:

    CC_TEST_REPORTER_ID=...
    

    Run:

    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