|
| 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}" |
0 commit comments