Home

Awesome

Ubuntu Mac OS Windows Public workflows that use this action.

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

All Contributors

<!-- ALL-CONTRIBUTORS-BADGE:END -->

coverage-badge-go

<img align="right" width="250px" src="https://user-images.githubusercontent.com/17484350/138557170-d8079b94-a517-4366-ade8-8d473e3f3f1d.jpg">

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@v4
        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@v4
        with:
          go-version-file: 'go.mod'

      - 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@v16
        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

<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
- uses: tj-actions/coverage-badge-go@v2
  id: coverage-badge-go
  with:
    # Color of the badge - green/yellow/red
    # Type: string
    color: ''

    # File containing the tests output
    # Type: string
    # Default: "coverage.out"
    filename: ''

    # At what percentage does the badge become green instead 
    # of yellow (default: 70) 
    # Type: string
    green: ''

    # Optional URL when you click the badge
    # Type: string
    link: ''

    # Target file (default "README.md")
    # Type: string
    target: ''

    # Text on the left side of the badge (default: "Coverage") 
    # Type: string
    text: ''

    # Text on the right side of the badge
    # Type: string
    value: ''

    # At what percentage does the badge become yellow instead 
    # of red (default 30) 
    # Type: string
    yellow: ''

<!-- AUTO-DOC-INPUT:END -->

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:

Contributors ✨

Thanks goes to these wonderful people (emoji key):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="14.28%"><a href="https://github.com/mdonahue-godaddy"><img src="https://avatars.githubusercontent.com/u/81647737?v=4?s=100" width="100px;" alt="Michael Donahue"/><br /><sub><b>Michael Donahue</b></sub></a><br /><a href="https://github.com/tj-actions/coverage-badge-go/issues?q=author%3Amdonahue-godaddy" title="Bug reports">🐛</a> <a href="https://github.com/tj-actions/coverage-badge-go/commits?author=mdonahue-godaddy" title="Code">💻</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification. Contributions of any kind welcome!