codeclimate / test-reporter

Code Climate Test Reporter
MIT License
156 stars 76 forks source link

Cannot upload coverage if not using GOPATH for Go projects. #363

Closed F21 closed 6 years ago

F21 commented 6 years ago

I am using Go 1.11 with Go modules. When Go modules are used, it's possible to build projects outside of the GOPATH. For example, rather than placing the project inside /pipeline/source/github.com/user/repo, we can clone the project directly into /pipeline/source.

The test-reporter currently does not support this. It throws an error because it's looking for files in the github.com/user/repo folder when the files are directly in the /pipeline/source folder:

export WERCKER_STEP_ROOT="/pipeline/script-bc7c76fc-bfc7-45fa-960a-657d7935684a"
export WERCKER_STEP_ID="script-bc7c76fc-bfc7-45fa-960a-657d7935684a"
export WERCKER_STEP_OWNER="wercker"
export WERCKER_STEP_NAME="script"
export WERCKER_REPORT_NUMBERS_FILE="/report/script-bc7c76fc-bfc7-45fa-960a-657d7935684a/numbers.ini"
export WERCKER_REPORT_MESSAGE_FILE="/report/script-bc7c76fc-bfc7-45fa-960a-657d7935684a/message.txt"
export WERCKER_REPORT_ARTIFACTS_DIR="/report/script-bc7c76fc-bfc7-45fa-960a-657d7935684a/artifacts"
source "/pipeline/script-bc7c76fc-bfc7-45fa-960a-657d7935684a/run.sh" < /dev/null
time="2018-09-19T04:10:50Z" level=debug msg="about to run format-coverage" 
time="2018-09-19T04:10:50Z" level=debug msg="searching for a formatter to use" 
time="2018-09-19T04:10:50Z" level=debug msg="checking excoveralls formatter" 
time="2018-09-19T04:10:50Z" level=debug msg="checking search path cover/excoveralls.json for excoveralls formatter" 
time="2018-09-19T04:10:50Z" level=debug msg="checking simplecov formatter" 
time="2018-09-19T04:10:50Z" level=debug msg="checking search path coverage/.resultset.json for simplecov formatter" 
time="2018-09-19T04:10:50Z" level=debug msg="checking gocov formatter" 
time="2018-09-19T04:10:50Z" level=debug msg="checking search path c.out for gocov formatter" 
time="2018-09-19T04:10:50Z" level=debug msg="found file c.out for gocov formatter" 
time="2018-09-19T04:10:50Z" level=debug msg="couldn't load committed at from ENV, trying git..." 
time="2018-09-19T04:10:50Z" level=info msg="trimming with prefix /pipeline/source/" 
time="2018-09-19T04:10:50Z" level=debug msg="getting fallback blob_id for source file github.com/Boostport/address/address.go" 
time="2018-09-19T04:10:50Z" level=error msg="failed to read file github.com/Boostport/address/address.go\nopen github.com/Boostport/address/address.go: no such file or directory" 
Error: open github.com/Boostport/address/address.go: no such file or directory
Usage:
  cc-test-reporter after-build [flags]

Flags:
  -s, --batch-size int               batch size for source files (default 500)
  -e, --coverage-endpoint string     endpoint to upload coverage information to (default "https://api.codeclimate.com/v1/test_reports")
  -t, --coverage-input-type string   type of input source to use [clover, cobertura, coverage.py, excoveralls, gcov, gocov, jacoco, lcov, simplecov]
      --exit-code int                exit code of the test run
  -r, --id string                    reporter identifier (default "2bc093d2d74702b0e5ebc9bbb0d38136b6dc2780b24e47250a5d963b3c881361")
      --insecure                     send coverage insecurely (without HTTPS)
  -p, --prefix string                the root directory where the coverage analysis was performed (default "/pipeline/source")

Global Flags:
  -d, --debug   run in debug mode
ale7714 commented 6 years ago

@F21 test-reporter is parsing the content on the c.out file, which probably has on it the full file paths. You could use the --prefix flag to remove github.com/Boostport/ and the test-reporter will be able to find the files. The invocation would look something like

cc-test-report after-build --prefix github.com/Boostport/

F21 commented 6 years ago

Thanks @ale7714. --prefix github.com/Boostport/address/ worked for me! 😄