Skip to content

Commit 8caf967

Browse files
committed
Extract mutation coverage badge step as reusable GitHub Action
1 parent 3327511 commit 8caf967

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Create Shields.io badge from PIT mutation test results
2+
author: Emil Lundberg <[email protected]>
3+
description: |
4+
Parses a [PIT][pitest] report file and outputs a [Shields.io][shields]
5+
[endpoint badge][endpoint] definition file.
6+
7+
[endpoint]: https://shields.io/endpoint
8+
[pitest]: https://pitest.org/
9+
[shields]: https://shields.io/
10+
11+
inputs:
12+
cache-seconds:
13+
default: 3600
14+
description: Passed through as cacheSeconds to Shields.io.
15+
16+
label:
17+
default: "mutation coverage"
18+
description: Label for the left side of the badge.
19+
20+
mutations-file:
21+
default: build/reports/pitest/mutations.xml
22+
description: Path to the PIT report XML file.
23+
24+
output-file:
25+
required: true
26+
description: Path to write output file to.
27+
28+
runs:
29+
using: "composite"
30+
31+
steps:
32+
- name: Install yq (and xq)
33+
shell: bash
34+
run: pip install yq
35+
36+
- name: Create coverage badge
37+
shell: bash
38+
run: |
39+
cat ${{ inputs.mutations-file }} \
40+
| xq '.mutations.mutation
41+
| (map(select(.["@detected"] == "true")) | length) / length
42+
| {
43+
schemaVersion: 1,
44+
label: "${{ inputs.label }}",
45+
message: "\(. * 100 | floor | tostring) %",
46+
color: "hsl(\(. * 120 | floor | tostring), 100%, 40%",
47+
cacheSeconds: ${{ inputs.cache-seconds }},
48+
}' \
49+
> ${{ inputs.output-file }}

.github/workflows/coverage.yml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ jobs:
3333
name: pitest-reports-${{ github.sha }}
3434
path: "*/build/reports/pitest/**"
3535

36-
- name: Install yq (and xq)
37-
run: |
38-
pip install yq
39-
4036
- name: Create output directory
4137
run: mkdir -p build/gh-pages
4238

@@ -51,18 +47,9 @@ jobs:
5147
- name: Create coverage badge
5248
# This creates a file that defines a [Shields.io endpoint badge](https://shields.io/endpoint)
5349
# which we can then include in the project README.
54-
run: |
55-
cat build/reports/pitest/mutations.xml \
56-
| xq '.mutations.mutation
57-
| (map(select(.["@detected"] == "true")) | length) / length
58-
| {
59-
schemaVersion: 1,
60-
label: "mutation coverage",
61-
message: "\(. * 100 | floor | tostring) %",
62-
color: "hsl(\(. * 120 | floor | tostring), 100%, 40%",
63-
cacheSeconds: 3600,
64-
}' \
65-
> build/gh-pages/coverage-badge.json
50+
uses: ./.github/actions/pit-results-badge
51+
with:
52+
output-file: build/gh-pages/coverage-badge.json
6653

6754
- name: Check out GitHub Pages branch
6855
uses: actions/checkout@v3

0 commit comments

Comments
 (0)