playwright/.github/workflows/create_test_report.yml
Yury Semikhatsky 7d2201561f
chore(devops): add check status for report merger to PRs (#23564)
The check summary has a link to the report and a link to the merge
workflow run. Otherwise it's very hard to tell which merge workflow
corresponds to given PR.
2023-06-06 22:45:57 -07:00

115 lines
4.8 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 into HTML Report
run: |
npx playwright merge-reports --reporter 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: |
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 {
const fs = require('fs');
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 { data: response } = await github.rest.issues.createComment({
...context.repo,
issue_number: prNumber,
body: `"${{ github.event.workflow_run.name }}" [report](${reportUrl}).`,
});
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: 'Merged test results (${{ github.event.workflow_run.name }})',
summary: `Created [report](${reportUrl}). Merge [workflow run](${mergeWorkflowUrl}).`,
}
});