go-test-summary

command module
v0.0.0-...-e60f80e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 5 Imported by: 0

README

GitHub Action: go-test-summary

Concept inspired heavily by gotestsum and GitHub blog on step summaries

This is a GitHub action to run go test using the json formatted output from the test operation, then parsing and rendering the output to provide a nice summary. Injecting that into the $GITHUB_STEP_SUMMARY file (which exists as an environment variable in GitHub runners). If the test errors, the action will return the same exit code (and the output)

Inputs

Input Default Description
hideUntestedPackages false Whether to minimise output for packages with no tests
workingDirectory '.' Directory where your go.mod file is located
testDirectories '.' If you need, you can run tests on newline separated sub-paths

Usage

In GitHub actions

You should be able to hot-swap your existing go test step with usage of this GHA like so:

name: on-push-test-and-build-app

on: push

jobs:
  test-and-build-app:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        name: Checkout Repo

      - name: Setup Go 1.21.0
        uses: actions/setup-go@v4
        with:
          go-version: '^1.21.0'

-      - name: Run Go Test
-        run: go test ./...
+      - name: Go Test -> Summary
+        uses: dmatryx/go-test-summary@v1.1

      - name: Build
        run: CGO_ENABLED=0 GOOS=linux go build -o my-app-name .
Output

Across these two images you can see how the collapseable sections will show/hide details - by default everything starts non-expanded but can toggle at a click.

If you do not specify to hide untested packages, you will have yellow summary sections indicating packages without tests

If you have failing tests, you can dig into the tests and output to see easily what has failed

go-test-summary-failing-verbose.png

If you have no problems at all, and have passing tests, and specify to hide untested packages you'll get a more succinct output like this:

go-test-summary-passing-brief.png

Again, all sections can be toggled. Non-test output, tests, subtests, test output, and anything else that can be hidden will all be hidden in an expandable section waiting for you to show what you want to see.

If you want to run this locally for some reason

Not really designed to be run locally, but you can grab and compile the binary itself. The program only requires one environment variable, and that's $GITHUB_STEP_SUMMARY - This is where the markdown file will be output to.

It's also worth noting that the Markdown generated is GitHub Flavour Markdown, which may or may not be supported by whatever you are trying to view it through.

Development

Contributions

I'm all ears, but don't be a douche and declare into the void that the project is abandoned if you don't get a response to your issue immediately.

Future ideas
  • Probably add some tests (oh the irony)
  • Provide the coverage output as a file in the repo's wiki
  • Maybe re-use the feature from go-coverage-report below for coverage buttons
Releases

Releases are generated by a local build, then pushing the binary to the releases branch. From there, standard Github release procedure.

Random other references

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL