ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - gha-common/go-beautiful-html-coverage: A GitHub Action to track code coverage in your pull requests, with a beautiful HTML preview, for free.
A GitHub Action to track code coverage in your pull requests, with a beautiful HTML preview, for free. - gha-common/go-beautiful-html-coverage
Visit Site

GitHub - gha-common/go-beautiful-html-coverage: A GitHub Action to track code coverage in your pull requests, with a beautiful HTML preview, for free.

GitHub - gha-common/go-beautiful-html-coverage: A GitHub Action to track code coverage in your pull requests, with a beautiful HTML preview, for free.

go-beautiful-html-coverage

Mentioned in Awesome Go

A GitHub Action to track code coverage in your pull requests, with a beautiful HTML preview โ†—, for free.

Usage

To use this action simply add it to your pre-existent ci workflow. A bare minimal example might look like this:

name: Go

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  test:
    name: Build and Test
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write        # required for posting comments
      contents: write             # required for git push
    steps:
      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5

      - name: Test                # this should generate cover.out
        run: make test

      - name: Go Beautiful HTML Coverage
        uses: 'gha-common/go-beautiful-html-coverage@v1'

How it works

This GHA expects cover.out to be present in the root of your repo at runtime. cover.out is usually generated by go test when passing the -coverprofile=cover.out flag:

go test -coverprofile=cover.out ./...

For examples on how you might do that you can peak at go-test-app/Makefile, or some of my other go projects like pretender and base-go-cli.

Once your test has ran and cover.out has been generated, the GHA does the following:

  1. Create and push new orphan branch if one doesn't exist.
  2. Generate cover.html and cover.txt from cover.out.
  3. Customize cover.html and rename it <sha>.html.
  4. git-push the <sha>.html file to the orphan branch. This will trigger a GitHub Pages deployment.
  5. Post a comment to your PR with your code coverage summary (cover.txt) and a link to your <sha>.html.

Screenshots

[!NOTE] In order for the HTML preview links to work, configure GitHub Pages in your target repo (Settings > Pages) to Deploy from a branch and pick your target branch, which is, by default, cover.

GitHub Pages Setup

Reference

- name: Go Beautiful HTML Coverage
  uses: 'gha-common/go-beautiful-html-coverage@v1'
  with:
    # Repository name with owner. For example, actions/checkout.
    # Default: ${{ github.repository }}
    repository: ''

    # The branch to checkout or create and push coverage to.
    # Default: 'cover'
    branch: ''

    # The token to use for pushing to the repository.
    # Default: ${{ github.token }}
    token: ''

    # The relative path of your go project. Useful for monorepos and custom folder structures.
    # Default: ./
    path: ''

    # The minimum % of coverage required.
    # Default: 0
    threshold: ''

Examples

You can customize the name of the branch that hosts the code coverage files.

- name: Go Beautiful HTML Coverage
  uses: 'gha-common/go-beautiful-html-coverage@v1'
  with:
    branch: 'my-coverage'

Just make sure to update the GitHub Pages deployment settings to match.

You can customize the repository that hosts the code coverage files.

This is helpful if you don't want to clutter your project's repo, or if you want to centralize coverage reporting across multiple repos, or you can't turn on GitHub Pages in your project's repo.

- name: Go Beautiful HTML Coverage
  uses: 'gha-common/go-beautiful-html-coverage@v1'
  with:
    repository: yourname/coverage
    token: ${{ secrets.GHA_COVERAGE_TOKEN }}

Where GHA_COVERAGE_TOKEN is a repository secret with a personal token that has write access to yourname/coverage.

You can customize the path to your go project in the repo.

This is helpful if you have a monorepo with multiple apps, or simply you keep your go files in a subfolder. Just make sure to generate cover.out for all your apps before running this GHA.

- name: Go Beautiful HTML Coverage
  uses: 'gha-common/go-beautiful-html-coverage@v1'
  with:
    path: ./go-app-01

- name: Go Beautiful HTML Coverage
  uses: 'gha-common/go-beautiful-html-coverage@v1'
  with:
    path: ./go-app-02

License

MIT License, see LICENSE

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory