Publish Test Results #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: Publish Test Results | |
on: | |
workflow_run: | |
workflows: [Test code] | |
types: [completed] | |
workflow_call: | |
jobs: | |
publish-test-results: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.event == 'pull_request' && !contains(fromJSON('["skipped", "cancelled"]'), github.event.workflow_run.conclusion) }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os_name: [ubuntu, windows, macos] | |
permissions: | |
checks: write | |
pull-requests: write | |
steps: | |
- name: Download and Extract Artifacts | |
uses: dawidd6/action-download-artifact@v6 | |
with: | |
run_id: ${{ github.event.workflow_run.id }} | |
name: artifact_${{ matrix.os_name }}_tests | |
path: artifacts | |
- name: Fetch PR number | |
id: pr | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const maxAttempts = 5; | |
let attempt = 0; | |
let pullRequestNumber; | |
while (attempt < maxAttempts) { | |
try { | |
const response = await github.rest.search.issuesAndPullRequests({ | |
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', | |
per_page: 1, | |
}); | |
const items = response.data.items; | |
if (items.length < 1) { | |
throw new Error('No PRs found'); | |
} | |
pullRequestNumber = items[0].number; | |
console.info("Pull request number is", pullRequestNumber); | |
break; // Exit loop on success | |
} catch (error) { | |
console.error(`Attempt ${attempt + 1} failed:`, error.message); | |
if (attempt < maxAttempts - 1) { // Check if not last attempt | |
console.log(`Waiting for 2 minutes before retrying...`); | |
await new Promise(resolve => setTimeout(resolve, 120000)); // Wait for 2 minutes | |
} | |
} | |
attempt++; | |
} | |
if (!pullRequestNumber) { | |
core.setFailed("Failed to fetch PR number after 5 attempts"); | |
} | |
return pullRequestNumber; | |
- name: Publish Test Results | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
header: test-results-${{ matrix.os_name }} | |
number: ${{ steps.pr.outputs.result }} | |
recreate: true | |
path: artifacts/.results_tests/github_report.md | |
- name: Add workflow link to comment | |
uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
header: test-results-${{ matrix.os_name }} | |
number: ${{ steps.pr.outputs.result }} | |
append: true | |
message: |- | |
<p><a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}">Link to workflow run</a></p> |