Comment on Playwright Test Results #142
This file contains hidden or 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: Comment on Playwright Test Results | |
| on: | |
| workflow_run: | |
| workflows: ['Playwright Tests'] | |
| types: | |
| - completed | |
| jobs: | |
| comment: | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion == 'failure' | |
| steps: | |
| - name: Download workflow artifact | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id, | |
| }); | |
| let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == "playwright-report" | |
| })[0]; | |
| if (matchArtifact) { | |
| let download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| let fs = require('fs'); | |
| fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/playwright-report.zip`, Buffer.from(download.data)); | |
| } | |
| - name: Get PR number | |
| uses: actions/github-script@v7 | |
| id: get-pr-number | |
| with: | |
| script: | | |
| if (context.payload.workflow_run.event === 'pull_request') { | |
| const { data: pullRequests } = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| head: `${context.payload.workflow_run.head_repository.owner.login}:${context.payload.workflow_run.head_branch}`, | |
| }); | |
| if (pullRequests.length > 0) { | |
| return pullRequests[0].number; | |
| } | |
| } | |
| return null; | |
| result-encoding: string | |
| - name: Comment on PR | |
| if: steps.get-pr-number.outputs.result != 'null' | |
| uses: thollander/actions-comment-pull-request@v3 | |
| with: | |
| pr-number: ${{ steps.get-pr-number.outputs.result }} | |
| message: | | |
| ### 🎭 Playwright tests failed | |
| The Playwright tests failed on this PR. Please check the test results and fix any issues. | |
| 📊 [View full test report](https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}) | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| mode: upsert | |
| create-if-not-exists: true |