Fixes ``` Notice: Report url: https://mspwblobreport.z1.web.core.windows.net/run-5533005176-1-a0b0752662f8af5f841ff7a65b04d02066474ff2/index.html ReferenceError: fs is not defined at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15143:16), <anonymous>:30:18) at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15144:12) at main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15236:26) at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:15217:1 at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:15268:3 at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:152[71](https://github.com/microsoft/playwright/actions/runs/5533535965/jobs/10097205178#step:12:72):12) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) ```
125 lines
5.1 KiB
YAML
125 lines
5.1 KiB
YAML
name: Publish Test Results
|
|
on:
|
|
workflow_run:
|
|
workflows: ["tests 1", "tests 2"]
|
|
types:
|
|
- completed
|
|
jobs:
|
|
merge-reports:
|
|
permissions:
|
|
pull-requests: write
|
|
checks: write
|
|
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
|
|
if: ${{ always() && github.event.workflow_run.event == 'pull_request' }}
|
|
uses: ./.github/actions/download-artifact
|
|
with:
|
|
name: 'blob-report-${{ github.event.workflow_run.run_attempt }}'
|
|
path: 'blob-report'
|
|
|
|
- name: Read pull request number
|
|
if: ${{ always() && github.event.workflow_run.event == 'pull_request' }}
|
|
uses: ./.github/actions/download-artifact
|
|
with:
|
|
name: 'pull-request'
|
|
path: './'
|
|
|
|
- name: Download blob report from Azure
|
|
if: ${{ always() && github.event.workflow_run.event == 'push' }}
|
|
uses: ./.github/actions/download-blob-report-from-azure
|
|
with:
|
|
blob_prefix: 'run-${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}-${{ github.sha }}'
|
|
output_dir: 'blob-report'
|
|
connection_string: '${{ secrets.AZURE_CONNECTION_STRING_FOR_BLOB_REPORT }}'
|
|
|
|
- name: Merge reports
|
|
run: |
|
|
npx playwright merge-reports --reporter markdown,html --attachments missing blob-report
|
|
|
|
- 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: Upload blob report to Azure
|
|
if: ${{ github.event.workflow_run.event == 'pull_request' }}
|
|
run: |
|
|
REPORT_DIR='run-${{ github.event.workflow_run.id }}-${{ github.event.workflow_run.run_attempt }}-${{ github.sha }}'
|
|
az storage blob upload-batch -s blob-report -d "\$web/$REPORT_DIR" --connection-string "${{ secrets.AZURE_CONNECTION_STRING_FOR_BLOB_REPORT }}"
|
|
|
|
- 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 if (context.payload.workflow_run.event === 'push') {
|
|
const { data } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
|
...context.repo,
|
|
commit_sha: context.sha,
|
|
});
|
|
prNumber = data[0].number;
|
|
} 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`;
|
|
core.notice('Report url: ' + reportUrl);
|
|
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 for "${{ github.event.workflow_run.name }}"`,
|
|
reportMd,
|
|
'---',
|
|
`Full [html report](${reportUrl}).`
|
|
].join('\n'),
|
|
});
|
|
core.info('Posted comment: ' + response.html_url);
|
|
|
|
const mergeWorkflowUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
|
|
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'),
|
|
}
|
|
});
|