Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ncruces/go-coverage-report
GitHub Action to add a coverage badge to your Go repo
https://github.com/ncruces/go-coverage-report
coverage github-actions go golang
Last synced: 1 day ago
JSON representation
GitHub Action to add a coverage badge to your Go repo
- Host: GitHub
- URL: https://github.com/ncruces/go-coverage-report
- Owner: ncruces
- License: mit
- Created: 2023-01-27T13:53:19.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-20T10:25:15.000Z (5 months ago)
- Last Synced: 2024-12-15T02:04:37.574Z (8 days ago)
- Topics: coverage, github-actions, go, golang
- Language: Shell
- Homepage: https://github.com/marketplace/actions/go-coverage-report
- Size: 29.3 KB
- Stars: 76
- Watchers: 2
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go coverage report
A GitHub Action to add a coverage [report][1], [badge][2], and [chart][4] to your Go repo.
Apply it to your repo by adding this step to one of your workflows:
```yaml
- name: Update coverage report
uses: ncruces/go-coverage-report@v0
```Your repo needs to have a Wiki for the action to work,
and workflows need to have read _and_ write permissions to the repo.The action has 8 configuration knobs:
- `coverage-file`: optional coverage input file;
default is to generate coverage for all packages in the current module.
- `output-dir`: optional output directory for the for the badge, report, chart;
default is to generate files to the root of wiki.
- `badge-style`: optional coverage badge style,
generated by [shields.io](https://shields.io);
one of: `flat` (default), `flat-square`, `plastic`, `for-the-badge`, `social`.
- `badge-title`: optional coverage badge title;
default is “coverage.”
- `report`: default `true`,
generate an [HTML coverage report][1].
- `chart`: default `false`,
generate an [SVG coverage chart][4].
- `amend`: default `false`,
amend your Wiki, avoiding a series of “Update coverage” commits.Also, consider:
- running this step _after_ your tests run
- coverage will fail if any test fails, so you may skip it if they fail
- running it only once per commit
- use a condition to avoid repeated matrix runs
- skipping it for PRs
- PRs lack permission to update the Wiki,
nor would you want unsubmitted PRs to do so
- allowing it to fail without failing the entire job
- if tests pass, the problem might be with the action itself, not your codeComplete example:
```yaml
- name: Test
run: go test -v ./...- name: Update coverage report
uses: ncruces/go-coverage-report@v0
with:
report: true
chart: true
amend: true
if: |
matrix.os == 'ubuntu-latest' &&
github.event_name == 'push'
continue-on-error: true
```The action generates an [HTML report][1], [SVG badge][2] and [chart][4],
and saves them as “hidden” files in your Wiki.> [!NOTE]
> The [HTML coverage report][1] can't be rendered for private repositories.To add a coverage badge to your `README.md`, use this Markdown snippet:
```markdown
[![Go Coverage](https://github.com/USER/REPO/wiki/coverage.svg)](https://raw.githack.com/wiki/USER/REPO/coverage.html)
```Clicking on the badge opens the [coverage report][1].
If you also want to show the [coverage chart][4],
create a [Wiki page][5] and link to it instead.The action will also [log][3] to the Wiki the unix timestamp and coverage of every run,
so it can generate the [coverage chart][4].[1]: https://raw.githack.com/wiki/ncruces/go-sqlite3/coverage.html
[2]: https://github.com/ncruces/go-sqlite3/wiki/coverage.svg
[3]: https://github.com/ncruces/go-sqlite3/wiki/coverage.log
[4]: https://github.com/ncruces/go-sqlite3/wiki/coverage-chart.svg
[5]: https://github.com/ncruces/go-sqlite3/wiki/Test-coverage-report## Credits
- [@vieux](https://github.com/vieux/) for [gocover.io](https://github.com/vieux/gocover.io) which I've used for years before creating this
- [@Prounckk](https://github.com/Prounckk) for the [blog](https://eremeev.ca/posts/golang-test-coverage-github-action/) that prompted this solution
- [raw.githack.com](https://raw.githack.com/) for proxying the HTML report
- [shields.io](https://shields.io/) for SVG badges
- [quickchart.io](https://quickchart.io/) for SVG charts