summaryrefslogtreecommitdiff
path: root/.github/workflows/playwright_comment.yml
blob: 8c33b618557dbd6e08a81a008f08b87977d6ec87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Comment on the PR with Playwright results

on:
  workflow_run:
    workflows: ["Playwright Tests"]
    types:
      - completed
permissions: {}
jobs:
  playwright_comment:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    if: >
      github.event.workflow_run.event == 'pull_request' &&
      github.event.workflow_run.conclusion == 'success'
    steps:
      - name: Grab playwright-output from PR run
        uses: dawidd6/action-download-artifact@5e780fc7bbd0cac69fc73271ed86edf5dcb72d67 # pin@v2
        continue-on-error: true
        id: playwright-output
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          run-id: ${{ github.event.workflow_run.id }}
          name: playwright-output

      - name: Grab master-screenshots-outcome from PR run
        uses: dawidd6/action-download-artifact@5e780fc7bbd0cac69fc73271ed86edf5dcb72d67 # pin@v2
        continue-on-error: true
        id: master-screenshots-outcome
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          run-id: ${{ github.event.workflow_run.id }}
          name: master-screenshots-outcome

      - name: Load artifacts into environment variables
        id: playwright
        run: |
          EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
          echo "PLAYWRIGHT_OUTPUT<<$EOF" >> $GITHUB_OUTPUT
          cat ./playwright-output >> $GITHUB_OUTPUT
          echo "$EOF" >> $GITHUB_OUTPUT
          echo "NUM_FAILED=$(grep -c 'Screenshot comparison failed' $GITHUB_OUTPUT)" >> $GITHUB_OUTPUT

      - name: "[Comment] Couldn't download screenshots from master branch"
        uses: mshick/add-pr-comment@a65df5f64fc741e91c59b8359a4bc56e57aaf5b1 # pin@v2
        if: github.event_name == 'pull_request' && steps.master-screenshots-outcome == 'failure'
        with:
          message: |
            :heavy_exclamation_mark: Could not fetch screenshots from master branch, so had nothing to make a visual comparison against; please check the "master-screenshots" step in the workflow run and rerun it before merging.

      - name: "[Comment] Success: No visual differences introduced by this PR"
        uses: mshick/add-pr-comment@a65df5f64fc741e91c59b8359a4bc56e57aaf5b1 # pin@v2
        if: github.event_name == 'pull_request' && steps.master-screenshots-outcome != 'failure' && steps.playwright.outputs.NUM_FAILED == 0
        with:
          message: |
            :heavy_check_mark: No visual differences introduced by this PR.
            [View Playwright Report](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}#artifacts) (note: open the "playwright-report" artifact)

      - name: "[Comment] Warning: Visual differences introduced by this PR"
        uses: mshick/add-pr-comment@a65df5f64fc741e91c59b8359a4bc56e57aaf5b1 # pin@v2
        if: github.event_name == 'pull_request' && steps.master-screenshots-outcome != 'failure' && steps.playwright.outputs.NUM_FAILED != 0
        with:
          message: |
            :warning: ${{ steps.playwright.outputs.NUM_FAILED }} visual differences introduced by this PR; please validate if they are desirable.
            <details>
            <summary>Playwright Test Results</summary>
            <pre>
            ${{ steps.playwright.outputs.PLAYWRIGHT_OUTPUT }}
            </pre>
            </details>
            [View Playwright Report](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}#artifacts) (note: open the "playwright-report" artifact)