A clover test coverage checker for Github Actions.
Simply add the following step to your workflow:
- name: Check test coverage
id: test-coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
with:
percentage: "95"
filename: "coverage.xml"
Using a badge action, you can create a badge based on the code coverage:
- name: Check test coverage
uses: johanvanhelden/gha-clover-test-coverage-check@v1
id: coverage
with:
percentage: "50"
filename: "coverage.xml"
- name: Generate the badge SVG image
uses: emibcn/badge-action@v1
id: badge
with:
label: 'Coverage'
status: ${{ steps.coverage.outputs.coverage }}
path: ./badges/test-coverage.svg
color: ${{ steps.coverage.outputs.coveragelines > 75 && 'green' || 'red' }}
If you want more colors and gradients, you can set it up the color
property like this:
color: ${{
steps.coverage.outputs.coverage > 90 && 'green' ||
steps.coverage.outputs.coverage > 80 && 'yellow,green' ||
steps.coverage.outputs.coverage > 70 && 'yellow' ||
steps.coverage.outputs.coverage > 60 && 'orange,yellow' ||
steps.coverage.outputs.coverage > 50 && 'orange' ||
steps.coverage.outputs.coverage > 40 && 'red,orange' ||
steps.coverage.outputs.coverage > 30 && 'red,red,orange' ||
steps.coverage.outputs.coverage > 20 && 'red,red,red,orange' ||
'red' }}
The minimum percentage of coverage allowed.
The filename of the clover coverage XML file.
The precision of the rounded coverage value. Where 0
will round to the highest rounded number (e.g: 99.999999
> 100
). By default: 2
.
Whether the coverage check should exit if the required percentage is not met. By default: true
.
The metric to get and process. By default: elements
.
Output is exported as GitHub Action output.
You can use it in other steps, for example:
- name: Test coverage
run: echo "${{ steps.test-coverage.outputs.coverage }}"
Or make a step conditional:
- name: Test coverage report
if: steps.test-coverage.outputs.coverage > 50
run: echo "We are more than halfway there!"
The calculated coverage value.
The calculated coverage value for display purposes.
The rounded coverage value.
The rounded calculated coverage value for display purposes.
The true or false value of the check result.
You can use this output with the exit
input to implement your own coverage logic.
This is how you can generate a test coverage report using PHPUnit:
- name: Generate code coverage
run: ./vendor/bin/phpunit --coverage-clover ./coverage.xml
You can test the action locally by running: docker-compose up --build
Any arguments can be configured in the docker-compose.yml
file.
Building happens automatically once a new version is tagged.
To push a manual build, ensure you are logged in locally to hub.docker.com using docker login
and have access to the hub repository.
(note: your username is used, not your email address).
$ docker build ./ --tag johanvanhelden/gha-clover-test-coverage-check:TAG
$ docker push johanvanhelden/gha-clover-test-coverage-check:TAG
Replace TAG
with the tag you are working on.