Publish Test Results #1758
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: ["tests 1", "tests 2"] | |
types: | |
- completed | |
jobs: | |
merge-reports: | |
permissions: | |
pull-requests: write | |
checks: write | |
if: ${{ github.event.workflow_run.event == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
- run: npm ci | |
env: | |
DEBUG: pw:install | |
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1 | |
- run: npm run build | |
- name: Download blob report artifact | |
uses: ./.github/actions/download-artifact | |
with: | |
name: all-blob-reports | |
path: all-blob-reports | |
- name: Merge reports | |
run: | | |
npx playwright merge-reports --reporter markdown,html ./all-blob-reports | |
- name: Upload HTML report to Azure | |
run: | | |
REPORT_DIR='run-${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}-${{ github.sha }}' | |
az storage blob upload-batch -s playwright-report -d "\$web/$REPORT_DIR" --connection-string "${{ secrets.AZURE_CONNECTION_STRING_FOR_BLOB_REPORT }}" | |
echo "Report url: https://mspwblobreport.z1.web.core.windows.net/$REPORT_DIR/index.html" | |
- name: Read pull request number | |
uses: ./.github/actions/download-artifact | |
with: | |
name: 'pull-request' | |
path: './' | |
- name: Comment on PR | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const fs = require('fs'); | |
let prNumber; | |
if (context.payload.workflow_run.event === 'pull_request') { | |
const prs = context.payload.workflow_run.pull_requests; | |
if (prs.length) { | |
prNumber = prs[0].number; | |
} else { | |
prNumber = parseInt(fs.readFileSync('pull_request_number.txt').toString()); | |
console.log('Read pull request number from file: ' + prNumber); | |
} | |
} else { | |
core.error('Unsupported workflow trigger event: ' + context.payload.workflow_run.event); | |
return; | |
} | |
if (!prNumber) { | |
core.error('No pull request found for commit ' + context.sha + ' and workflow triggered by: ' + context.payload.workflow_run.event); | |
return; | |
} | |
const reportDir = 'run-${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}-${{ github.sha }}'; | |
const reportUrl = `https://mspwblobreport.z1.web.core.windows.net/${reportDir}/index.html#?q=s%3Afailed%20s%3Aflaky`; | |
core.notice('Report url: ' + reportUrl); | |
const mergeWorkflowUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; | |
const reportMd = await fs.promises.readFile('report.md', 'utf8'); | |
const { data: response } = await github.rest.issues.createComment({ | |
...context.repo, | |
issue_number: prNumber, | |
body: [ | |
`### [Test results](${reportUrl}) for "${{ github.event.workflow_run.name }}"`, | |
reportMd, | |
'', | |
`Merge [workflow run](${mergeWorkflowUrl}).` | |
].join('\n'), | |
}); | |
core.info('Posted comment: ' + response.html_url); | |
const check = await github.rest.checks.create({ | |
...context.repo, | |
name: 'Merge report (${{ github.event.workflow_run.name }})', | |
head_sha: '${{ github.event.workflow_run.head_sha }}', | |
status: 'completed', | |
conclusion: 'success', | |
details_url: reportUrl, | |
output: { | |
title: 'Test results for "${{ github.event.workflow_run.name }}"', | |
summary: [ | |
reportMd, | |
'---', | |
`Full [HTML report](${reportUrl}). Merge [workflow run](${mergeWorkflowUrl}).` | |
].join('\n'), | |
} | |
}); |