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
59 stars 11 forks source link

Action does not work. Always creates comment with "Merging this branch will not change overall coverage" #21

Closed piotrowski closed 5 months ago

piotrowski commented 6 months ago

image

Hello! I decided to try your Action, unfortunatelly for some reason it always shows 0 on every touched file.

This is how I am using your action. I have this 3 steps in 1 job:

      - name: generate test coverage
        run: go test -cover -coverprofile=coverage.txt ./...

      - name: Archive code coverage results
        uses: actions/upload-artifact@v4
        with:
          name: code-coverage
          path: coverage.txt
          retention-days: 2

      - uses: fgrosse/go-coverage-report@v1.0.0 
        if: ${{ github.event_name == 'pull_request' }}
        with:
          coverage-artifact-name: "code-coverage"
          coverage-file-name: "coverage.txt" 
fgrosse commented 6 months ago

Could it be that your Go import path is different from your filesystem path? In that case, you may have to provide the root-package input to the action. Note that currently, packages with a different name than their directory are not supported. More information can be found here: https://github.com/fgrosse/go-coverage-report/blob/7469ef95bb02bcdd817b88dc54f67099320d9f37/action.yml#L28-L36

Apart from that, I suggest to use a longer retention period for your code coverage artifacts because these are also used when comparing your new coverage with the baseline of your main branch. If you submit a PR after the retention time, this baseline can no longer be found and the coverage check will fail.

piotrowski commented 5 months ago

Thank you! root-package helped!