Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeClimate Report for Go doesn't work #109

Closed
toshimaru opened this issue Feb 21, 2020 · 19 comments
Closed

CodeClimate Report for Go doesn't work #109

toshimaru opened this issue Feb 21, 2020 · 19 comments
Assignees
Labels
bug Something isn't working

Comments

@toshimaru
Copy link

toshimaru commented Feb 21, 2020

Error

Actions Result URL: https://github.com/toshimaru/nyan/runs/459063904

./cc-reporter after-build --exit-code 0
time="2020-02-20T23:26:31Z" level=error msg="failed to read file github.com/toshimaru/nyan/main.go\nopen github.com/toshimaru/nyan/main.go: no such file or directory" 
Error: open github.com/toshimaru/nyan/main.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, xccov]
      --exit-code int                exit code of the test run
  -r, --id string                    reporter identifier (default "f4c78effd3a10a5a45239e6886b35f42475467ad53f09a01002feeb04eb92d5b")
      --insecure                     send coverage insecurely (without HTTPS)
  -p, --prefix string                the root directory where the coverage analysis was performed (default "/home/runner/work/nyan/nyan")

Global Flags:
  -d, --debug   run in debug mode

##[error]Error: The process './cc-reporter' failed with exit code 255
##[error]🚨 CC Reporter after-build checkin failed!
(node:2888) UnhandledPromiseRejectionWarning: Error: The process './cc-reporter' failed with exit code 255
    at ExecState._setResult (/home/runner/work/_actions/paambaati/codeclimate-action/v2.4.0/node_modules/@actions/exec/lib/toolrunner.js:548:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/paambaati/codeclimate-action/v2.4.0/node_modules/@actions/exec/lib/toolrunner.js:531:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/paambaati/codeclimate-action/v2.4.0/node_modules/@actions/exec/lib/toolrunner.js:431:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
(node:2888) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2888) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My Setting

    steps:
    - uses: actions/setup-go@v2-beta
      with:
        go-version: '^1.13.8'
    ...
    - uses: paambaati/[email protected]
      env:
        CC_TEST_REPORTER_ID: ...
      with:
        coverageCommand: go test ./... -coverprofile c.out

Other information

cc-test-reporter on TravisCI works with the following setting.

...
before_script:
  - 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
script:
  - go build .
  - go test ./... -coverprofile c.out
after_script:
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@ccremer
Copy link

ccremer commented Feb 22, 2020

This also hit me. Key is to make the --prefix configurable as well in this action.

Until this is resolved, I'm working around it:

    - name: Download codeclimate reporter
      run: wget -O cc-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 && chmod +x cc-reporter
    - name: Prepare code coverage
      run: ./cc-reporter before-build
    - name: Run unit tests
      run: go test -coverprofile=c.out ./...
    - name: Format code coverage
      run: ./cc-reporter format-coverage c.out -t gocov -p $(basename $PWD)
    - name: Upload code coverage
      env:
        CC_TEST_REPORTER_ID: ...
      run: ./cc-reporter after-build -t gocov -p $(basename $PWD)

@paambaati
Copy link
Owner

paambaati commented Feb 25, 2020

@toshimaru @ccremer I've created a PR (#111) that attempts to include support for a custom prefix. Can you try it out?

You'll have to modify your action YAML to use —

steps:
  - name: Test & publish code coverage
    uses: paambaati/codeclimate-action@prefix-support

@ccremer
Copy link

ccremer commented Feb 25, 2020

Hi, thanks for getting into this!

Unfortunately it fails with Error:

##[error]File not found: '/home/runner/work/_actions/paambaati/codeclimate-action/prefix-support/lib/main.js'

https://github.com/ccremer/znapzend-exporter/pull/2/checks?sha=f96a6c101dba6e92b92a4815f618b66203959ffd

@paambaati paambaati reopened this Feb 25, 2020
@paambaati
Copy link
Owner

@ccremer Sorry, but can you try again? I just pushed a new release.

steps:
  - name: Test & publish code coverage
    uses: paambaati/[email protected]

@ccremer
Copy link

ccremer commented Feb 25, 2020

Seems to work 🎉

https://github.com/ccremer/znapzend-exporter/runs/467246099?check_suite_focus=true

@toshimaru
Copy link
Author

It worked! 👍
https://github.com/toshimaru/nyan/pull/73/checks?check_run_id=468919116

@paambaati Thanks for you quick work :)

@toshimaru
Copy link
Author

@paambaati
The action succeeded, but the reporting seems not work.
toshimaru/nyan#73

I put some captures on the PR, diff-coverage and total-coverage have not been reported properly.

@paambaati
Copy link
Owner

@toshimaru Thanks, can you show me reports/logs? I'm still trying to understand how exactly the reporter itself works (note that this action is only a small wrapper for the reporter).

@toshimaru
Copy link
Author

@paambaati

this is whole log:

https://github.com/toshimaru/nyan/runs/468939395

/home/runner/work/nyan/nyan/cc-reporter after-build --exit-code 0 --prefix 
time="2020-02-26T04:55:41Z" level=error msg="failed to read file github.com/toshimaru/nyan/main.go\nopen github.com/toshimaru/nyan/main.go: no such file or directory" 
Error: open github.com/toshimaru/nyan/main.go: no such file or directory
Usage:
  cc-test-reporter after-build [flags]

image

image

@ccremer
Copy link

ccremer commented Feb 26, 2020

@toshimaru Why is the prefix empty? For Go it's needed to give the prefix that is named the same as the directory (I think, or is it the Go module 🤔 )

@paambaati
Copy link
Owner

@toshimaru I've pushed a fix for this. Can you try v2.5.3?

@toshimaru
Copy link
Author

@ccremer
Yes, you're right, I added prefix option and set it properly, then it works! Thank you 💯

@paambaati
I use v2.5.3, but it doesn't work since it doesn't set prefix correctly:
https://github.com/toshimaru/nyan/runs/470034484

I re-use v2.5.0 and add prefix, it works:
https://github.com/toshimaru/nyan/runs/470074429

@paambaati
Copy link
Owner

paambaati commented Feb 26, 2020

@toshimaru So I looked at your workflow YAML, and you’re using your project’s Github URL as the prefix, when you should be giving it the test directory path. Skipping it will default to the current working directory, which works for most use-cases.

From https://docs.codeclimate.com/docs/configuring-test-coverage

You may need to specify a prefix value if your tests are run outside of your project's root directory.

For example, if you're running tests within a docker container and your app code is located at /usr/src/app, you'd use:

cc-test-reporter format-coverage --prefix /usr/src/app

@paambaati paambaati self-assigned this Feb 26, 2020
@paambaati paambaati added the bug Something isn't working label Feb 26, 2020
@sundowndev
Copy link

This is not working for me either : https://github.com/dreamvo/gilfoyle/runs/1400610928

/home/runner/work/gilfoyle/gilfoyle/cc-reporter format-coverage /home/runner/work/gilfoyle/gilfoyle/c.out -t gocov -o codeclimate.0.json --debug --prefix gilfoyle
time="2020-11-14T19:02:56Z" level=debug msg="coverage path /home/runner/work/gilfoyle/gilfoyle/c.out" 
time="2020-11-14T19:02:56Z" level=debug msg="using formatter gocov" 
time="2020-11-14T19:02:56Z" level=debug msg="checking search path /home/runner/work/gilfoyle/gilfoyle/c.out for gocov formatter" 
time="2020-11-14T19:02:57Z" level=debug msg="couldn't load committed at from ENV, trying git..." 
time="2020-11-14T19:02:57Z" level=info msg="trimming with prefix gilfoyle/" 
time="2020-11-14T19:02:57Z" level=debug msg="getting fallback blob_id for source file github.com/dreamvo/gilfoyle/api/api.go" 
time="2020-11-14T19:02:57Z" level=error msg="failed to read file github.com/dreamvo/gilfoyle/api/api.go\nopen github.com/dreamvo/gilfoyle/api/api.go: no such file or directory" 
Error: open github.com/dreamvo/gilfoyle/api/api.go: no such file or directory
Usage:
  cc-test-reporter format-coverage [coverage file] [flags]

Flags:
      --add-prefix string   add this prefix to file paths
  -t, --input-type string   type of input source to use [clover, cobertura, coverage.py, excoveralls, gcov, gocov, jacoco, lcov, simplecov, xccov]
  -o, --output string       output path (default "coverage/codeclimate.json")
  -p, --prefix string       the root directory where the coverage analysis was performed (default "/home/runner/work/gilfoyle/gilfoyle")

Global Flags:
  -d, --debug   run in debug mode

Error: The process '/home/runner/work/gilfoyle/gilfoyle/cc-reporter' failed with exit code 255
(node:5701) UnhandledPromiseRejectionWarning: Error: The process '/home/runner/work/gilfoyle/gilfoyle/cc-reporter' failed with exit code 255
    at ExecState._setResult (/home/runner/work/_actions/paambaati/codeclimate-action/v2.7.4/node_modules/@actions/exec/lib/toolrunner.js:574:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/paambaati/codeclimate-action/v2.7.4/node_modules/@actions/exec/lib/toolrunner.js:557:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/paambaati/codeclimate-action/v2.7.4/node_modules/@actions/exec/lib/toolrunner.js:451:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
(node:5701) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:5701) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error: 🚨 CC Reporter coverage formatting failed!

config:

      - name: Test
        uses: paambaati/[email protected]
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TOKEN }}
        with:
          debug: true
          coverageCommand: go test -race -coverprofile=c.out -covermode=atomic -v -bench=. ./...
          prefix: ${{ github.event.repository.name }}
          coverageLocations: |
            ${{github.workspace}}/c.out:gocov

Any advice ? Thanks

@ccremer
Copy link

ccremer commented Dec 26, 2020

I figured out more. The code climate reporter really depends on what is configured in go.mod.
this example here:

module github.com/ccremer/clustercode
go 1.15
require (
...
)

doesn't work with

    - name: Test & Publish Code Coverage
      uses: paambaati/[email protected]
      env:
        CC_TEST_REPORTER_ID: ...
      with:
        coverageCommand: make test
        prefix: ${{ github.event.repository.name }}
        coverageLocations:
          "${{github.workspace}}/cover.out:gocov"

The problematic line is module github.com/ccremer/clustercode in go.mod. If it were just module clustercode, then the config works.
So I made a little hack by just removing the github.com/ccremer/ prefix from the cover file:

.PHONY: test_codeclimate
test_codeclimate: test ## Run tests for CodeClimate
	@sed -i "s%github.com/ccremer/%%" cover.out

and combine with coverageCommand: make test_codeclimate
Now it works for me.

@denbon05
Copy link

denbon05 commented Jul 6, 2022

https://github.com/denbon05/fastify-lcache/runs/7219367431?check_suite_focus=true
I have a similar issue for nodejs on pull-request :/
In other cases it looks fine.
Can you give some advice?
image

@TatisLois
Copy link

@denbon05 were you able to figure it out, ran into a similar issue

@denbon05
Copy link

@TatisLois I think I figured it out. People who makes pull-request don't have CC_TEST_REPORTER_ID in secretes so I added in my yml file into .github/workflows/ condition if github.event_name != 'pull_request'. Thanks for your response.

YU-K added a commit to YU-K/python-project-50 that referenced this issue Jan 8, 2024
@ekristen
Copy link

ekristen commented Jan 23, 2024

This is still broken. It takes the value from go.mod and breaks looking at the path.

If you set prefix to the entirety of what is in go.mod it seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants