paambaati / codeclimate-action

GitHub Action to send your code coverage to CodeClimate
MIT License
200 stars 63 forks source link

TypeError: Cannot read properties of undefined (reading 'split') #630

Closed Synertry closed 1 year ago

Synertry commented 1 year ago

Describe the bug The action errors after generating the coverage with:

/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/glob/lib/internal-globber.js:173
            const lines = patterns.split('\n').map(x => x.trim());
                                   ^

TypeError: Cannot read properties of undefined (reading 'split')
    at Function.<anonymous> (/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/glob/lib/internal-globber.js:173:36)
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/glob/lib/internal-globber.js:27:71
    at new Promise (<anonymous>)
    at __awaiter (/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/glob/lib/internal-globber.js:23:12)
    at Function.create (/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/glob/lib/internal-globber.js:167:16)
    at Object.<anonymous> (/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/glob/lib/glob.js:23:56)
    at Generator.next (<anonymous>)
    at /home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/glob/lib/glob.js:8:71
    at new Promise (<anonymous>)

Version of codeclimate-action you're using v3.2.0

Example links

  1. Configure your job to include the debug: true flag and the ACTIONS_STEP_DEBUG secret to true so I can get additional debugging information. Both enabled, but enabling ACTIONS_STEP_DEBUG secret does not show more useful info at all.

  2. Include links to the specific Github action run and your config. https://github.com/Synertry/RushDevsDailyGo/actions/runs/3307664720/jobs/5459463366

Expected behavior Finishing the step by uploading the coverage without errors

Additional context Step configuration:

      - name: Generate Code Coverage & report to Codeclimate
        if: needs.precheck.outputs.doc_only != 'true'
        uses: paambaati/codeclimate-action@v3.2.0
        env:
          # Set CC_TEST_REPORTER_ID as secret of your repo
          CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
        with:
          # The report file must be there, otherwise Code Climate won't find it
          coverageCommand: go test -v -race -vet off -covermode atomic -coverprofile coverage.out ./Daily/...
          coverageLocations: |
            coverage.out
          debug: true
paambaati commented 1 year ago

@Synertry Would you mind reviewing the documentation once again? The coverageLocations should be of the form <location>:<type>.

So it should look like this –

coverageLocations: |
        ${{github.workspace}}/*.lcov:lcov

or –

coverageLocations: ${{github.workspace}}/target/site/jacoco/jacoco.xml:jacoco
Synertry commented 1 year ago

I tried it with:

for the coverage from go, but it fails while trying to open one of the main files:

/home/runner/work/RushDevsDailyGo/RushDevsDailyGo/cc-reporter format-coverage /home/runner/work/RushDevsDailyGo/RushDevsDailyGo/coverage.out -t gocov -o codeclimate.0.json
Error: time="2022-10-25T08:36:44Z" level=error msg="failed to read file github.com/Synertry/RushDevsDailyGo/Daily/0001.intersection/intersection.go\nopen github.com/Synertry/RushDevsDailyGo/Daily/0001.intersection/intersection.go: no such file or directory" 
/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/exec/lib/toolrunner.js:592
                error = new Error(`The process '${this.toolPath}' failed with exit code ${this.processExitCode}`);
                        ^

Error: The process '/home/runner/work/RushDevsDailyGo/RushDevsDailyGo/cc-reporter' failed with exit code 255
    at ExecState._setResult (/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/exec/lib/toolrunner.js:592:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/exec/lib/toolrunner.js:575:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/paambaati/codeclimate-action/v3.2.0/node_modules/@actions/exec/lib/toolrunner.js:469:27)
    at ChildProcess.emit (node:events:[390](https://github.com/Synertry/RushDevsDailyGo/actions/runs/3319369312/jobs/5484454487#step:9:391):28)
    at maybeClose (node:internal/child_process:1064:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
Error: Error: open github.com/Synertry/RushDevsDailyGo/Daily/0001.intersection/intersection.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, lcov-json, 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/RushDevsDailyGo/RushDevsDailyGo")

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

Error: The process '/home/runner/work/RushDevsDailyGo/RushDevsDailyGo/cc-reporter' failed with exit code 255
Error: 🚨 CC Reporter coverage formatting failed!

It is unfortunately not really clear which type I have to use for Go. The main docs states Cover which the cli does not support, but in contrary has a suggestive gocov.

paambaati commented 1 year ago

I would recommend you follow the documentation and try to run the reporter locally, and see if it can parse and process the coverage output correctly.

This action is just a simple wrapper to the reporter, and this error is coming from the reporter itself and not the action; unfortunately, I’m not a Go expert either, so I’m afraid I can’t help here.

Here’s where I’d start —

  1. Figure out what the coverage output is - this includes the output path and the format
  2. Make sure you’re using the correct paths and format
  3. Run reporter locally and see if it can process it as expected
Synertry commented 1 year ago

Took the third step to heart and quickly set up a Docker instance for testing. The format is gocov, but more importantly I was missing the prefix.

Final working config for Golang:

      - name: Generate Code Coverage & report to Codeclimate
        uses: paambaati/codeclimate-action@v3.2.0
        env:
          # Set CC_TEST_REPORTER_ID as secret of your repo
          CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
        with:
          # The report file must be there, otherwise Code Climate won't find it
          coverageCommand: go test -v -race -vet off -covermode atomic -coverprofile coverage.out ./Daily/...
          coverageLocations: ${{ github.workspace }}/coverage.out:gocov
          prefix: github.com/Synertry/RushDevsDailyGo

Thank you for your time and help + awesome Github action!👍💯