Skip to content

PR - test results comment #2129

PR - test results comment

PR - test results comment #2129

name: PR - test results comment
on:
workflow_run:
workflows: ["Build, test and package"]
types:
- completed
defaults:
run:
shell: pwsh
jobs:
main:
name: Add test results as PR comment
if: github.event.workflow_run.event == 'pull_request'
permissions:
contents: read
pull-requests: write
strategy:
fail-fast: false # don't fail if one of the matrix jobs fails. Example: try to add test results as comments for the ubuntu matrix even if the windows matrix fails.
matrix:
include:
- test-results-artifact-name: "test-results-ubuntu-latest"
os: "ubuntu-latest"
- test-results-artifact-name: "test-results-windows-latest"
os: "windows-latest"
runs-on: ubuntu-latest
env:
TEST_RESULTS_ARTIFACT_NAME: ${{ matrix.test-results-artifact-name }}
steps:
- name: Dump github context for debug purposes
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: $env:GITHUB_CONTEXT
- name: Download artifact
uses: dawidd6/action-download-artifact@v6
with:
name: ${{ env.TEST_RESULTS_ARTIFACT_NAME }}
run_id: ${{ github.event.workflow_run.id }}
path: ${{ env.TEST_RESULTS_ARTIFACT_NAME }}
- name: Sanitize PR test results comment
id: sanitize-pr-comment
run: |
$commentBody = "# [Test runs on ${{ matrix.os }}](${{ github.event.workflow_run.html_url }}) for commit ${{ github.event.workflow_run.head_sha }}`n`n"
$commentBody += Get-Content ./${{ env.TEST_RESULTS_ARTIFACT_NAME }}/*.md
$random = Get-Random
$delimiter = "EOF_$random"
Write-Output "pr-comment-body<<$delimiter" >> $env:GITHUB_OUTPUT
Write-Output $commentBody >> $env:GITHUB_OUTPUT
Write-Output $delimiter >> $env:GITHUB_OUTPUT
- name: Update PR with test results
uses: edumserrano/find-create-or-update-comment@v3
with:
issue-number: ${{ github.event.workflow_run.pull_requests[0].number }}
body-includes: '<!-- on-pr-test-results-${{ matrix.os }} -->'
comment-author: github-actions[bot]
body: ${{ steps.sanitize-pr-comment.outputs.pr-comment-body }}
edit-mode: replace