Generate a coverage badge like this one for your go projects.
👇
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 # Pass the `coverage.out` output to this action
run:
go test -v ./... -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
- name: Go Coverage Badge
uses: tj-actions/coverage-badge-go@v1
with:
filename: coverage.out
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v8.1
id: verify-changed-files
with:
files: README.md
- name: Push changes
if: steps.changed_files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ github.token }}
branch: ${{ github.head_ref }}
- Generate coverage badge from a coverage report.
Input | type | required | default | description |
---|---|---|---|---|
filename | string |
true |
coverage.out |
File containing the tests output (default: "coverage.out") |
- Free software: MIT license
If you feel generous and want to show some extra appreciation:
This package was created with Cookiecutter using cookiecutter-action
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.