5aaee9 / go-coverage-report

GitHub Action to add a coverage badge to your Go repo

Home Page:https://github.com/marketplace/actions/go-coverage-report

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go coverage report

A GitHub Action to add a coverage report, badge, and chart to your Go repo.

Apply it to your repo by adding this step to one of your workflows:

- 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 3 configuration knobs:

  • report: default true, whether to generate an HTML coverage report.
  • chart: default false, whether to generate an SVG coverage chart.
  • amend: default false, whether to 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 badge, nor would you want them to
  • allowing it to fail without failing the entire job
    • if tests pass, the problem might be with the badge itself, not your code

Complete example:

- name: Test
  run: go test -v ./...

- name: Update coverage report
  uses: ncruces/go-coverage-report@v0
  with:
    report: 'true'
    chart: 'true'
    amend: 'false'
  if: |
    matrix.os == 'ubuntu-latest' &&
    github.event_name == 'push'  
  continue-on-error: true

The action generates an HTML report, SVG badge and chart, and saves them as “hidden” files in your Wiki.

To add a coverage badge to your README.md, use this Markdown snippet:

[![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. If you also want to show the coverage chart, create a Wiki page to display both.

The action will also log to the Wiki the unix timestamp and coverage of every run, which it uses to generate the coverage chart.

Use manually or as a pre-commit hook

The script can also be run manually, or as a pre-commit hook.

Credits

About

GitHub Action to add a coverage badge to your Go repo

https://github.com/marketplace/actions/go-coverage-report

License:MIT License


Languages

Language:Shell 100.0%