Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
check-circle

GitHub Action

Go Coverage Badge

v2.4

Go Coverage Badge

check-circle

Go Coverage Badge

Generate coverage badge for go projects

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Go Coverage Badge

uses: tj-actions/coverage-badge-go@v2.4

Learn more about this action in tj-actions/coverage-badge-go

Choose a version

Ubuntu Mac OS Windows Public workflows that use this action.

coverage-badge-go

Generate a coverage badge like this one for your Golang projects without uploading results to a third party.

              👇

CI Coverage Update release version.

Usage

name: Generate code coverage badge

on:
  pull_request:
    branches:
      - main

jobs:
  test:
    runs-on: ubuntu-latest
    name: Update coverage badge
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
          fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
      
      - name: Setup go
        uses: actions/setup-go@v2
        with:
          go-version: '1.14.4'

      - uses: actions/cache@v2
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: Run Test
        run: |
          go test -v ./... -covermode=count -coverprofile=coverage.out
          go tool cover -func=coverage.out -o=coverage.out

      - name: Go Coverage Badge  # Pass the `coverage.out` output to this action
        uses: tj-actions/coverage-badge-go@v2
        with:
          filename: coverage.out

      - name: Verify Changed files
        uses: tj-actions/verify-changed-files@v12
        id: verify-changed-files
        with:
          files: README.md

      - name: Commit changes
        if: steps.verify-changed-files.outputs.files_changed == 'true'
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"
          git add README.md
          git commit -m "chore: Updated coverage badge."

      - name: Push changes
        if: steps.verify-changed-files.outputs.files_changed == 'true'
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ github.token }}
          branch: ${{ github.head_ref }}

Signed commits

In order to create signed commits see full guide here

Inputs

INPUT TYPE REQUIRED DEFAULT DESCRIPTION
color string false Color of the badge -
green/yellow/red
filename string true "coverage.out" File containing the tests output
green string false At what percentage does the
badge become green instead of
yellow (default: 70)
link string false Optional URL when you click
the badge
target string false Target file (default "README.md")
text string false Text on the left side
of the badge (default: "Coverage")
value string false Text on the right side
of the badge
yellow string false At what percentage does the
badge become yellow instead of
red (default 30)

If you feel generous and want to show some extra appreciation:

Buy me a coffee

Credits

This package was created with Cookiecutter using cookiecutter-action

Report Bugs

Report bugs at https://github.com/tj-actions/coverage-badge-go/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your workflow that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.