https://github.com/jbunds/coverage
Go coverage HTML report generator
https://github.com/jbunds/coverage
ci ci-cd cicd coverage coverage-report developer-tools devtools go golang golang-tools testing testing-tool testing-tools
Last synced: about 2 months ago
JSON representation
Go coverage HTML report generator
- Host: GitHub
- URL: https://github.com/jbunds/coverage
- Owner: jbunds
- License: mit
- Created: 2026-03-23T00:08:25.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-04-22T09:38:44.000Z (about 2 months ago)
- Last Synced: 2026-04-22T11:34:11.055Z (about 2 months ago)
- Topics: ci, ci-cd, cicd, coverage, coverage-report, developer-tools, devtools, go, golang, golang-tools, testing, testing-tool, testing-tools
- Language: Go
- Homepage:
- Size: 2.66 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/jbunds/coverage/blob/main/go.mod) [](https://github.com/pre-commit/pre-commit) [](https://github.com/jbunds/coverage/actions/workflows/test-go.yml) [](https://github.com/jbunds/coverage/actions/workflows/test-go.yml) [](https://github.com/jbunds/coverage/actions/workflows/lint-go.yml) [](https://github.com/neostandard/neostandard)
[simple-tree]: https://github.com/psnet/simple-tree
[k8s]: https://github.com/kubernetes/kubernetes
[light theme]: ./screenshots/light_theme.jpg "light theme"
[dark theme]: ./screenshots/dark_theme.jpg "dark theme"
[gwatts-gocov-action]: https://github.com/gwatts/go-coverage-action
[gwatts-gocov-outputs]: https://github.com/gwatts/go-coverage-action/blob/main/action.yml
[action]: https://github.com/jbunds/coverage/blob/main/action.yml
[workflow]: https://github.com/jbunds/coverage/blob/main/.github/workflows/pages.yml
[actions]: https://docs.github.com/actions
[workflows]: https://docs.github.com/actions/concepts/workflows-and-actions/workflows
[pages]: https://docs.github.com/pages
#### Simple Web UI for Go Test Coverage
Drop-in replacement for `go tool cover -html`.
The `coverage` Go module renders an HTML file for each `*.go` source file listed in the specified Go test coverage profile file (typically created per an invocation of `go test -coverprofile `).
The program expects the specification of three flags with corresponding arguments (see [usage](#cli-usage) below):
```
-gomod # path to the root go.mod file
-coverprofile # path to the Go test coverage profile file
-path # path where HTML files will be written
```
The generated HTML files are marked up to identify which lines are covered by tests ($\color{seagreen}{\text{green}}$), and which lines are not ($\color{red}{\text{red}}$). Each HTML file is written to the specified path (per the `-path` flag) following the same directory structure as the source from which the coverage profile file (per the `-coverprofile` flag) was created.
The program then creates a `tree.html` file which provides a navigable view of the source rendered as a directory tree within an iframe on the left, where each node is either a subdirectory (`📁 `) or a source file (`.go`). Clicking on a subdirectory node expands its contents, and clicking on a source file node renders the marked up source in the iframe to the right of the directory tree.
Both iframes are hosted by a parent `index.html` file, and both HTML files can be inspected in a browser, either directly via the `file://` scheme, or via an HTTP server using the `http://` scheme.
When served via HTTP, buttons are available to:
-
toggle between **light** and **dark** themes
-
toggle between a fully-collapsed and fully-expanded directory tree
See also [](https://deepwiki.com/jbunds/coverage) and [](https://pkg.go.dev/github.com/jbunds/coverage)
---
#### User Interface
[demo.webm](https://github.com/user-attachments/assets/e3651efe-e468-4d0e-8f41-e601e0fa429a)
**light** theme:
![light theme][light theme]
**dark** theme:
![dark theme][dark theme]
---
#### CLI Usage
```
$ go get github.com/jbunds/coverage
$ go run github.com/jbunds/coverage
coverage usage:
-coverprofile string
path to Go test coverage profile file
-gomod string
path to the root go.mod file
-path string
path where HTML files will be written
```
---
#### GitHub Workflow Configuration
Aside from the [CLI interface](#cli-usage) outlined above, there are two ways to incorporate the `coverage` module within [GitHub workflows][workflows]:
1. The [`jbunds/coverage@v1`][action] reusable [GitHub Action][actions] generates the test coverage report and writes the files comprising the report to `coverage-report-path`. For example:
```
- uses: jbunds/coverage@v1
with:
go-version: '1.26.2' # optional; default is '1.26.2'
go-mod: 'go.mod' # optional; default is 'go.mod'
coverage-threshold: '50' # optional; default is '0'
coverage-report-path: 'coverage_report' # optional; default is 'coverage_report'
```
The [`go-version`][action], [`go-mod`][action], [`coverage-threshold`][gwatts-gocov-outputs], and [`coverage-report-path`][workflow] parameters are optional.
All [outputs][gwatts-gocov-outputs] produced by the [`gwatts/go-coverage-action`][gwatts-gocov-action] workflow step are available downstream via JSON decoding, e.g.:
```
${{ fromJson(steps.coverage_report.outputs.all).gcov-pathname }}
${{ fromJson(steps.coverage_report.outputs.all).report-pathname }}
${{ fromJson(steps.coverage_report.outputs.all).coverage-pct }}
${{ fromJson(steps.coverage_report.outputs.all).coverage-pct-1dp }}
${{ fromJson(steps.coverage_report.outputs.all).meets-threshold }}
```
etc...
2. The [`jbunds/coverage/.github/workflows/pages.yml@v1`][workflow] reusable [GitHub Workflow][workflows] generates the test coverage report and also deploys it to [GitHub Pages][pages]. For example:
```
- uses: jbunds/coverage/.github/workflows/pages.yml@v1
with:
go-version: '1.26.2' # optional: default is '1.26.2'
go-mod: 'go.mod' # optional; default is 'go.mod'
coverage-threshold: '50' # optional; default is '0'
coverage-report-path: 'coverage_report' # optional; default is 'coverage_report'
```
See https://jbunds.github.io/coverage/ for an example, which is not particularly interesting since it consists of just the four Go source files which implement the module.
The well-known and relatively large (500k+ LoC) [Kubernetes][k8s] project was chosen for the demo to better illustrate the features and performance.
---
#### But _Why?_
The motivation for the `coverage` module was to create a relatively minimal alternative to the default HTML interface produced by `go tool cover -html -o `, with a simple and intuitive UI, and with minimal JavaScript (55 lines total as of this writing, to implement the functionality of the toggle buttons).
The CSS code was inspired by and adapted from [github.com/psnet/simple-tree][simple-tree], and it clearly still needs to be polished. But I am definitely _not_ a CSS expert, and it fulfills the required behavior as-is.