Skip to content

Commit 3327511

Browse files
committed
Extract PIT results comment step as reusable action
1 parent 57bf67a commit 3327511

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed
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}"

.github/workflows/coverage.yml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,16 @@ jobs:
7070
ref: gh-pages
7171
clean: false
7272

73-
- name: Post mutation test results as commit comment
73+
- name: Prepare metadata for pit-results-comment action
7474
run: |
75-
git checkout "${GITHUB_SHA}" -- .github/workflows/coverage
76-
77-
./.github/workflows/coverage/compute-stats.sh build/reports/pitest/mutations.xml > new-stats.json
78-
79-
if [[ -f prev-mutations.xml ]]; then
80-
./.github/workflows/coverage/compute-stats.sh prev-mutations.xml > prev-stats.json
81-
else
82-
cp new-stats.json prev-stats.json
83-
fi
84-
85-
touch prev-commit.txt
75+
git checkout "${GITHUB_SHA}" -- .github/workflows/coverage .github/actions
76+
echo PREV_COMMIT=$(cat prev-commit.txt) >> "${GITHUB_ENV}"
8677
87-
./.github/workflows/coverage/stats-to-comment.sh prev-stats.json new-stats.json $(cat prev-commit.txt) > build/results-comment.json
88-
89-
curl -X POST \
90-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
91-
${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/comments -d @build/results-comment.json
78+
- name: Post mutation test results as commit comment
79+
uses: ./.github/actions/pit-results-comment
80+
with:
81+
prev-commit: ${{ env.PREV_COMMIT }}
82+
prev-mutations-file: prev-mutations.xml
9283

9384
- name: Push to GitHub Pages
9485
run: |

0 commit comments

Comments
 (0)