An open API service indexing awesome lists of open source software.

https://github.com/linkdata/gitcoverage

Manage code coverage badges and reports
https://github.com/linkdata/gitcoverage

Last synced: 19 days ago
JSON representation

Manage code coverage badges and reports

Awesome Lists containing this project

README

          

[![coverage](https://github.com/linkdata/gitcoverage/blob/main/coverage_badge_animated.svg)](#)

# gitcoverage

Generate code coverage badge and push it and optional HTML report to the 'coverage' branch.

This action has no dependencies except for `git`, the `bash` shell and common *nix command line utilities
`awk`, `sed` and GNU coreutils (`mkdir, cp, rm, ls, cat, echo, printf`). This means it won't run on Windows
runners; use `if: runner.os != 'Windows'` to exclude those in the workflow.

Git features required by this action:
- `git worktree add --detach` (documented in Git 2.5.6)
- `git branch --format` (present in Git 2.13.7, absent in 2.12.5)
- `git rev-parse --is-shallow-repository` (added in Git 2.15 release notes)

Therefore, use **Git 2.15.0 or newer**.

## Usage

You need to have given write permissions for the for the workflow.
If the 'coverage' branch does not exist, it will be created as an orphan (without main repo history).
Reference the generated badge in your README.md like this:

```md
[![coverage](https://github.com/USERNAME/REPO/blob/coverage/BRANCH/badge.svg)](#)
```

If you submitted a detailed HTML report of the coverage to the action, replace the '#' with:

`https://html-preview.github.io/?url=https://github.com/USERNAME/REPO/blob/coverage/BRANCH/report.html`

### Inputs

- `coverage` (required): Coverage percentage (for example `83` or `83%`).
- `report` (optional): Path to an HTML report file to publish as `report.html`.
- `branch` (optional): Source branch override. Recommended for tag-triggered workflows where multiple branches may contain the same tag commit.
Also recommended for very large or restricted repos to avoid scanning all remote branches during tag-triggered branch resolution.

## Examples

Inside your .github/workflows/workflow.yml file:

```yml
permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: linkdata/gitcoverage@v3
with:
coverage: "83%"
report: "coveragereport.html.out"
```

More complete example using Go:

```yml
permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go:
- "stable"
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- name: Go Generate
run: go generate ./...

- name: Go Test
run: go test -coverprofile=coverage ./...

- name: Go Build
run: go build .

- name: Calculate code coverage
if: runner.os != 'Windows'
id: coverage
run: |
echo "COVERAGE=$(go tool cover -func=coverage | tail -n 1 | tr -s '\t' | cut -f 3)" >> $GITHUB_OUTPUT
go tool cover -html=coverage -o=coveragereport.html

- name: Publish code coverage badge (and optional report)
if: runner.os != 'Windows'
uses: linkdata/gitcoverage@v3
with:
coverage: ${{ steps.coverage.outputs.coverage }}
report: "coveragereport.html"
```

Tag workflow example with explicit source branch:

```yml
- name: Publish code coverage badge from tag build
uses: linkdata/gitcoverage@v3
with:
coverage: "91%"
branch: "release/1.x"
```