coverdata
easily converts Erlang cover
data files into a JSON object for simple
integration with a Shields IO Dynamic JSON
badge to show a code coverage level
updated with each build:
This repository creates an escript that reads
coverage data from .coverdata
files, outputting a JSON object of
the percentage coverage per module and the total coverage percentage.
Without an --input
argument cover2json
will import all .coverdata
files under the current directory.
cover2json --output _site/cover/coverage.json
Each module has a coverage rate, with total
being combined rate:
{
"total": 67,
"scran_combinator": 96,
"scran_debug": 0,
"scran_number_be": 5,
"scran_number": 23,
"scran_multi": 97,
"scran_bytes": 83,
"scran_branch": 100,
"scran_sequence": 95,
"scran_result": 33,
"scran_number_le": 0,
"scran_bits": 100,
"scran_character_complete": 98
}
Options:
--input
is a single filename of.coverdata
to load (optional)--output
is an output filename for the JSON object (required)--level LEVEL
is the analyse level for cover to use. Onlymodule
is supported at present, and is the default (optional)--format FORMAT
is the output format to use, currently onlyjson
is supported (default, optional).
coverdata
can be used as part of a GitHub Action copying the JSON
object into a GitHub Pages environment. A shields.io dynamic JSON
badge can then use the coverage.json
as input.
In this GitHub Action fragment:
site:
needs: build
strategy:
matrix:
otp:
- 26
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
- run: make tests edoc
- uses: shortishly/coverdata@main
with:
input: _site/cover
output: _site/cover/coverage.json
otp-version: ${{matrix.otp}}
- uses: actions/upload-pages-artifact@v1
with:
path: _site
The site
job runs the tests with coverage enabled, generating edoc
which are output into directories under _site
, which are then
uploaded to GitHub Pages via the
actions/upload-pages-artifact@v1
. Each successful build will update
the _site/cover/coverage.json
.
The README.md references the current coverage level via (using scran as a live example):
<a href="https://shortishly.github.io/scran/cover/">
<img alt="Test Coverage" src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fshortishly.github.io%2Fscran%2Fcover%2Fcoverage.json&query=%24.total&suffix=%25&style=flat-square&label=Test%20Coverage&color=green">
</a>
The encoded URL used points to the generated coverage.json
on the
GitHub Pages environment used by the project:
https://shortishly.github.io/scran/cover/coverage.json
The query into the JSON object is $.total
to select the total
coverage of the project within the badge.
coverdata
uses erlang.mk.
To fetch dependencies and compile:
make app
To run the unit tests:
make tests