fgrosse / go-coverage-report

A CLI tool and GitHub Action to post Go code coverage reports as comment to your pull requests.
BSD 3-Clause "New" or "Revised" License
53 stars 8 forks source link

Coverage $ and Δ display 0 in action comment #17

Closed Robert-MacWha closed 5 months ago

Robert-MacWha commented 5 months ago

As title says, when I run the provided sample workflow as part of my CI pipeline a comment is successfully generated, however, the comment does not display the correct information. Capture

I also cloned the go-coverage-report repo (https://github.com/Robert-MacWha/go-coverage-report/pull/1), removed some tests, and ran the CI workflow. This also resulted in no coverage info being displayed in the comment. Interestingly, when I logged the code coverage results, it seemed to correctly generate the oldCov and newCov structs.

+ go-coverage-report -root=github.com/Robert-MacWha/go-coverage-report -trim=github.com/fgrosse/go-coverage-report/ .github/outputs/old-coverage.txt .github/outputs/new-coverage.txt .github/outputs/all_changed_files.json
  Old Coverage: &{Files:map[github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/changed_files.go:0xc00006e050 github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/coverage.go:0xc00006e0a0 github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/main.go:0xc00006e0f0 github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/profile.go:0xc00006e140 github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/report.go:0xc00006e190] TotalStmt:336 CoveredStmt:200 MissedStmt:136}
  New Coverage: &{Files:map[github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/changed_files.go:0xc00006e1e0 github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/coverage.go:0xc00006e230 github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/main.go:0xc00006e280 github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/profile.go:0xc00006e2d0 github.com/fgrosse/go-coverage-report/cmd/go-coverage-report/report.go:0xc00006e320] TotalStmt:339 CoveredStmt:85 MissedStmt:254}
  Changed Files: [github.com/Robert-MacWha/go-coverage-report/cmd/go-coverage-report/coverage_test.go github.com/Robert-MacWha/go-coverage-report/cmd/go-coverage-report/main.go github.com/Robert-MacWha/go-coverage-report/cmd/go-coverage-report/report_test.go]

I'll see if I can fix things, if so will make a quick PR.

Robert-MacWha commented 5 months ago

I see — this might be intended behaviour.

Logging the ChangedPackages slice, it includes the repo in the package name, while the {old/new}CovPkgs do not.

  changed packages: [github.com/Robert-MacWha/go-coverage-report/cmd/go-coverage-report]
  old packages: map[cmd/go-coverage-report:0xc0000d61c0]
  new packages: map[cmd/go-coverage-report:0xc0000d6220]

This is because ChangedPackages pulls from the GitHub repository's name while {old/new}CovPkgs pulls from go.mod. I suppose this is why root-package exists, eh?

Robert-MacWha commented 5 months ago

Yep, that's the issue.

For anyone experiencing similar problems: make sure the value for root-package in the action workflow.yml matches the name of your module in go.mod.