Skip to content

Commit 09bc235

Browse files
committed
Merge branch 'main' into release-2.1.0
2 parents 6843b80 + fa04cff commit 09bc235

File tree

74 files changed

+959
-603
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+959
-603
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 }}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Post PIT mutation test results comment
2+
author: Emil Lundberg <[email protected]>
3+
description: |
4+
Parses a [PIT][pitest] report file, compares it to a previous report,
5+
and posts a summary as a commit comment to the commit that triggered the workflow.
6+
7+
[pitest]: https://pitest.org/
8+
9+
inputs:
10+
mutations-file:
11+
default: build/reports/pitest/mutations.xml
12+
description: Path to the PIT report XML file.
13+
14+
prev-commit:
15+
default: ''
16+
description: |
17+
The full commit SHA of the previous run of this action.
18+
If set, the comment will include a link to the previous commit.
19+
20+
prev-mutations-file:
21+
required: true
22+
description: Path to the PIT report XML file from the previous run of this action.
23+
24+
token:
25+
default: ${{ github.token }}
26+
description: GITHUB_TOKEN or a PAT with permission to write commit comments.
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: Post results comment
37+
shell: bash
38+
run: |
39+
RESULTS_COMMENT_FILE=$(mktemp)
40+
NEW_STATS_FILE=$(mktemp)
41+
PREV_STATS_FILE=$(mktemp)
42+
43+
./.github/actions/pit-results-comment/compute-stats.sh "${{ inputs.mutations-file }}" > "${NEW_STATS_FILE}"
44+
45+
if [[ -f "${{ inputs.prev-mutations-file }}" ]]; then
46+
./.github/actions/pit-results-comment/compute-stats.sh "${{ inputs.prev-mutations-file }}" > "${PREV_STATS_FILE}"
47+
else
48+
echo 'Previous mutations file not found, using current as placeholder.'
49+
cp "${NEW_STATS_FILE}" "${PREV_STATS_FILE}"
50+
fi
51+
52+
./.github/actions/pit-results-comment/stats-to-comment.sh "${PREV_STATS_FILE}" "${NEW_STATS_FILE}" "${{ inputs.prev-commit }}" > "${RESULTS_COMMENT_FILE}"
53+
54+
curl -X POST \
55+
-H "Authorization: Bearer ${{ inputs.token }}" \
56+
${{ github.api_url }}/repos/${{ github.repository }}/commits/${{ github.sha }}/comments -d @"${RESULTS_COMMENT_FILE}"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
xq '.mutations.mutation
4+
| group_by(.mutatedClass | split(".") | .[:-1])
5+
| INDEX(.[0].mutatedClass | split(".") | .[:-1] | join("."))
6+
| map_values({
7+
detected: (map(select(.["@detected"] == "true")) | length),
8+
mutations: length,
9+
})
10+
' "${1}"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
3+
make-contents() {
4+
cat << EOF
5+
## Mutation test results
6+
7+
Package | Coverage | Stats | Prev | Prev |
8+
------- | --------:|:-----:| ----:|:----:|
9+
EOF
10+
11+
jq -s '.[0] as $old | .[1] as $new
12+
| {
13+
packages: (
14+
$old | keys
15+
| map({
16+
("`\(.)`"): {
17+
before: {
18+
detected: $old[.].detected,
19+
mutations: $old[.].mutations,
20+
},
21+
after: {
22+
detected: $new[.].detected,
23+
mutations: $new[.].mutations,
24+
},
25+
percentage_diff: (($new[.].detected / $new[.].mutations - $old[.].detected / $old[.].mutations) * 100 | round),
26+
},
27+
})
28+
| add
29+
),
30+
overall: {
31+
before: {
32+
detected: [($old[] | .detected)] | add,
33+
mutations: [($old[] | .mutations)] | add,
34+
},
35+
after: {
36+
detected: [($new[] | .detected)] | add,
37+
mutations: [($new[] | .mutations)] | add,
38+
},
39+
percentage_diff: (
40+
(
41+
([($new[] | .detected)] | add) / ([($new[] | .mutations)] | add)
42+
- ([($old[] | .detected)] | add) / ([($old[] | .mutations)] | add)
43+
) * 100 | round
44+
),
45+
},
46+
}
47+
| { ("**Overall**"): .overall } + .packages
48+
| to_entries
49+
| .[]
50+
| def difficon:
51+
if .after.detected == .after.mutations then ":trophy:"
52+
elif .percentage_diff > 0 then ":green_circle:"
53+
elif .percentage_diff < 0 then ":small_red_triangle_down:"
54+
else ":small_blue_diamond:"
55+
end;
56+
def triangles:
57+
if . > 0 then ":small_red_triangle:"
58+
elif . < 0 then ":small_red_triangle_down:"
59+
else ":small_blue_diamond:"
60+
end;
61+
"\(.key) | **\(.value.after.detected / .value.after.mutations * 100 | floor) %** \(.value | difficon) | \(.value.after.detected) \(.value.after.detected - .value.before.detected | triangles) / \(.value.after.mutations) \(.value.after.mutations - .value.before.mutations | triangles)| \(.value.before.detected / .value.before.mutations * 100 | floor) % | \(.value.before.detected) / \(.value.before.mutations)"
62+
' \
63+
"${1}" "${2}" --raw-output
64+
65+
if [[ -n "${3}" ]]; then
66+
cat << EOF
67+
68+
Previous run: ${3}
69+
EOF
70+
71+
cat << EOF
72+
73+
Detailed reports: [workflow run #${GITHUB_RUN_NUMBER}](/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})
74+
EOF
75+
fi
76+
77+
}
78+
79+
make-contents "$@" | python -c 'import json; import sys; print(json.dumps({"body": sys.stdin.read()}))'

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ updates:
66
directory: "/"
77
schedule:
88
interval: "daily"
9+
10+
ignore:
11+
# Spotless patch updates are too noisy
12+
- dependency-name: "spotless-plugin-gradle"
13+
update-types: ["version-update:semver-patch"]
14+
15+
- package-ecosystem: "github-actions"
16+
directory: "/"
17+
schedule:
18+
interval: "weekly"

.github/workflows/build.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,48 @@ on:
1111

1212
jobs:
1313
test:
14-
name: JDK ${{matrix.java}}
14+
name: JDK ${{ matrix.java }} ${{ matrix.distribution }}
1515

1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
java: [8, 11, 16]
19+
java: [8, 11, 17, 18]
20+
distribution: [temurin]
21+
include:
22+
- java: 17
23+
distribution: zulu
24+
- java: 17
25+
distribution: microsoft
26+
27+
outputs:
28+
report-java: 17
29+
report-dist: temurin
2030

2131
steps:
2232
- name: Check out code
23-
uses: actions/checkout@v1
33+
uses: actions/checkout@v3
2434

2535
- name: Set up JDK
26-
uses: actions/setup-java@v1
36+
uses: actions/setup-java@v3
2737
with:
2838
java-version: ${{ matrix.java }}
39+
distribution: ${{ matrix.distribution }}
2940

3041
- name: Run tests
3142
run: ./gradlew cleanTest test
3243

3344
- name: Archive HTML test report
3445
if: ${{ always() }}
35-
uses: actions/upload-artifact@v2
46+
uses: actions/upload-artifact@v3
3647
with:
37-
name: test-reports-java${{ matrix.java }}-html
48+
name: test-reports-java${{ matrix.java }}-${{ matrix.distribution }}-html
3849
path: "*/build/reports/**"
3950

4051
- name: Archive JUnit test report
4152
if: ${{ always() }}
42-
uses: actions/upload-artifact@v2
53+
uses: actions/upload-artifact@v3
4354
with:
44-
name: test-reports-java${{ matrix.java }}-xml
55+
name: test-reports-java${{ matrix.java }}-${{ matrix.distribution }}-xml
4556
path: "*/build/test-results/**/*.xml"
4657

4758
- name: Build JavaDoc
@@ -53,11 +64,17 @@ jobs:
5364
runs-on: ubuntu-latest
5465
if: ${{ always() && github.event_name == 'pull_request' }}
5566

67+
permissions:
68+
checks: write
69+
pull-requests: write
70+
5671
steps:
5772
- name: Download artifacts
58-
uses: actions/download-artifact@v2
73+
uses: actions/download-artifact@v3
74+
with:
75+
name: test-reports-java${{ needs.test.outputs.report-java }}-${{ needs.test.outputs.report-dist }}-xml
5976

6077
- name: Publish test results
61-
uses: EnricoMi/publish-unit-test-result-action@v1
78+
uses: EnricoMi/publish-unit-test-result-action@v2
6279
with:
6380
files: "**/*.xml"

.github/workflows/code-formatting.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
java: [11]
19+
java: [17]
20+
distribution: [temurin]
2021

2122
steps:
2223
- name: Check out code
23-
uses: actions/checkout@v1
24+
uses: actions/checkout@v3
2425

2526
- name: Set up JDK
26-
uses: actions/setup-java@v1
27+
uses: actions/setup-java@v3
2728
with:
2829
java-version: ${{ matrix.java }}
30+
distribution: ${{ matrix.distribution }}
2931

3032
- name: Check code formatting
3133
run: ./gradlew spotlessCheck

.github/workflows/codeql-analysis.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ jobs:
1616

1717
runs-on: ubuntu-latest
1818

19+
permissions:
20+
security-events: write
21+
1922
steps:
2023
- name: Checkout repository
21-
uses: actions/checkout@v2
24+
uses: actions/checkout@v3
2225

23-
- uses: actions/setup-java@v1
26+
- uses: actions/setup-java@v3
2427
with:
25-
java-version: '11'
28+
java-version: 17
29+
distribution: temurin
2630

2731
# Initializes the CodeQL tools for scanning.
2832
- name: Initialize CodeQL
29-
uses: github/codeql-action/init@v1
33+
uses: github/codeql-action/init@v2
3034
with:
3135
languages: java
3236

@@ -35,4 +39,4 @@ jobs:
3539
./gradlew jar
3640
3741
- name: Perform CodeQL Analysis
38-
uses: github/codeql-action/analyze@v1
42+
uses: github/codeql-action/analyze@v2

0 commit comments

Comments
 (0)