Skip to content

ncruces/go-coverage-report

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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; 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.
  • chart: default false, generate an SVG coverage chart.
  • 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 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: true
  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.

Note

The HTML coverage report can't be rendered for private repositories.

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 and link to it instead.

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

Credits