GitHub Action for running go test ./... and getting rich summary and annotations as output.
Powered by Job Summaries, this Action will generate a convenient interactive viewer for tests based on Go's test2json output. If there are any errors during go test, the Action will report back the same exit code, which will fail the job.
- name: Test
uses: robherley/go-test-action@v1- uses: robherley/go-test-action@v1
with:
# Relative path to the directory containing the go.mod of the module you wish to test.
# Optional. Default is '.'
moduleDirectory:
# Arguments to pass to go test, -json will be prepended automatically.
# Optional. Default is './...'
testArguments:
# If true, appends `-cover` to the go test command. Skipped if testArguments
# already contains a -cover* flag (e.g. -coverprofile=...). Coverage is rendered
# as a column in the summary table.
# Optional. Default is 'false'
cover:
# Parse one or more [test2json](https://pkg.go.dev/cmd/test2json) files (newline-separated) and generate a combined summary.
# Will always exit(0) on successful test file parse.
# fromJSONFile is accepted as an alias for a single file.
# Optional. No default
fromJSONFiles:
# Whitespace separated list of renderable items to omit.
# Valid options to omit are:
# untested: packages that have no tests
# successful: packages that are successful
# pie: mermaid.js pie chart
# pkg-tests: per-package test list
# pkg-output: per-package test output
# stderr: standard error output of `go test` subprocess
# Optional. No default
omit:Here's a rendered output (with coverage) from robherley/go-test-example:
πΌοΈ Demo Test Summary
ββββββββββ 53.1% coverage
%%{init: {"theme":"base","themeVariables":{"fontFamily":"monospace","pieSectionTextSize":"24px","darkMode":true,"pie1":"#2da44e","pie2":"#cf222e","pie3":"#dbab0a"}}}%%
pie showData
"Passed" : 12
"Failed" : 2
"Skipped" : 1
| π¦ Package | π’ Passed | π΄ Failed | π‘ Skipped | β³ Duration | π Coverage | |
|---|---|---|---|---|---|---|
π‘ . (main) | 0 | 0 | 0 | 0ms | β | |
π§ͺ Tests(none)π¨οΈ Output | ||||||
π΄ boom | 0 | 2 | 0 | 6ms | β | |
π§ͺ Tests
π¨οΈ Output
| ||||||
π’ highcov | 7 | 0 | 0 | 4ms | 100% | ββββββββββ |
π§ͺ Tests
π¨οΈ Output | ||||||
π’ lowcov | 1 | 0 | 0 | 4ms | 6.2% | ββββββββββ |
π§ͺ Tests
π¨οΈ Output | ||||||
π’ skipme | 0 | 0 | 1 | 3ms | β | |
π§ͺ Tests
π¨οΈ Output | ||||||
π’ success | 4 | 0 | 0 | 2ms | β | |
π§ͺ Tests
π¨οΈ Output | ||||||
name: Go
on:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build
run: go build -v ./...
- name: Test
uses: robherley/go-test-action@v1When go test is invoked with -cover (or -coverprofile=...), the action parses the per-package coverage: X.Y% of statements lines and appends a π Coverage column to the summary table, plus the mean coverage to the header text.
Use the cover input as a shortcut to append -cover:
- name: Test
uses: robherley/go-test-action@v1
with:
cover: trueOr pass a coverage flag directly via testArguments:
- name: Test
uses: robherley/go-test-action@v1
with:
testArguments: '-coverprofile=coverage.out ./...'- name: Test
uses: robherley/go-test-action@v1
with:
fromJSONFiles: |
/path/to/pkg1-test2json.json
/path/to/pkg2-test2json.jsonSee Inputs above for valid options
- name: Test
uses: robherley/go-test-action@v1
with:
omit: |
pie
stderror
- name: Test
uses: robherley/go-test-action@v1
with:
omit: 'pie'