go-coverage-report icon indicating copy to clipboard operation
go-coverage-report copied to clipboard

Parsing issue

Open decisiveJoe opened this issue 9 months ago • 5 comments

I'm trying to use this action but running into a parsing error and I'm lost as to how to resolve it.

The error in the GH Action run:

  + go-coverage-report -root=github.com/<organization>/<repository> -trim= .github/outputs/old-coverage.txt .github/outputs/new-coverage.txt .github/outputs/all_modified_files.json
  ERROR: failed to parse old coverage: failed to parse profiles: bad mode line: github.com/<organization>/<repository>/api/v1/foo_types.go:207:			init						100.0%
  Error: Process completed with exit code 1.

Coverage file is coverage.txt and lines are formatted as:

github.com/<organization>/<repository>/api/v1/foo_types.go:207:			init						100.0%

The action step in the workflow is declared as:

      - name: Generate Code Coverage Report
        uses: fgrosse/[email protected]
        with:
          coverage-artifact-name: code-coverage # can be omitted if you used this default value
          coverage-file-name: coverage.txt # can be omitted if you used this default value

And I've verified that the action is able to download the correct artifacts, the names provided in this step are correct.

decisiveJoe avatar Mar 04 '25 16:03 decisiveJoe

For what it's worth, I've dug into the code for this action and did some checking with the formatting of go's coverage output for .out vs .txt files and it seems like this action requires .out formatted files. If that's the case, then an update to documentation should clear up the confusion.

decisiveJoe avatar Mar 05 '25 17:03 decisiveJoe

Hey Joe, this action does not require the .out format specifically and I'm using it only with the txt format so there must be some other issue.

The parsing error you shared is:

 ERROR: failed to parse old coverage: failed to parse profiles: bad mode line: github.com/<organization>/<repository>/api/v1/foo_types.go:207:			init						100.0%

This looks to me like it was trying to parse the cover mode line but in fact it found some code coverage for (100% of init in oo_types.go:207 was covered).

The first line in the coverage file should be something like this: mode: atomic. Can you check if this is there?

Also, if you can, maybe you want to share how you created the coverage profile and which version of Go you are using?

fgrosse avatar Mar 17 '25 07:03 fgrosse

By the way, I think the file extension you chose (i.e., .out vs .txt) doesn't matter, as it will consistently be formatted in the same way. I always use .txt to signal that this file contains a human-readable plaintext format.

fgrosse avatar Mar 17 '25 07:03 fgrosse

To debug the issue further on your side, I recommend using go tool cover to check if the produced coverage can be parsed by Go:

Example (run after switching inside your modules directory):

❯ go tool cover -func coverage.txt

fgrosse avatar Mar 17 '25 08:03 fgrosse

@fgrosse Thanks for getting back to me about this. I'm new to Go and working with some more experienced engineers, so I might not be fully understanding what is going on. When I passed -coverprofile=coverage.txt with my go test ... command, I received a human readable coverage breakdown that did not have the mode: atomic (or other mode type) lines in it.

However, when I passed -coverprofile=coverage.out, the format matched what your package expects.

Also, if you can, maybe you want to share how you created the coverage profile and which version of Go you are using?

Full test command: go test $$(go list ./... | grep -v -E "/e2e|/test/utils|cmd") -coverprofile=coverage.out Go version: go version go1.23.4 darwin/arm64

decisiveJoe avatar Mar 17 '25 14:03 decisiveJoe