Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)
1name: Comment on the PR with Playwright results
2
3on:
4 workflow_run:
5 workflows: ["Playwright Tests"]
6 types:
7 - completed
8permissions: {}
9jobs:
10 playwright_comment:
11 runs-on: ubuntu-latest
12 permissions:
13 pull-requests: write
14 if: >
15 github.event.workflow_run.event == 'pull_request' &&
16 github.event.workflow_run.conclusion == 'success'
17 steps:
18 - name: Harden Runner
19 uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
20 with:
21 egress-policy: audit
22
23 - name: Grab playwright-output from PR run
24 uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9
25 continue-on-error: true
26 with:
27 github_token: ${{ secrets.GITHUB_TOKEN }}
28 run_id: ${{ github.event.workflow_run.id }}
29 name: playwright-output
30
31 - name: Grab master-screenshots-outcome from PR run
32 uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9
33 continue-on-error: true
34 with:
35 github_token: ${{ secrets.GITHUB_TOKEN }}
36 run_id: ${{ github.event.workflow_run.id }}
37 name: master-screenshots-outcome
38 if: github.event_name == 'pull_request'
39
40 - name: Grab playwright-results-json from PR run
41 uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9
42 continue-on-error: true
43 with:
44 github_token: ${{ secrets.GITHUB_TOKEN }}
45 run_id: ${{ github.event.workflow_run.id }}
46 name: playwright-results-json
47
48 - name: Dry-run grab playwright-report from PR run so we have its ID
49 uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9
50 id: playwright-report
51 continue-on-error: true
52 with:
53 github_token: ${{ secrets.GITHUB_TOKEN }}
54 run_id: ${{ github.event.workflow_run.id }}
55 name: playwright-report
56 dry_run: true
57
58 - name: Store playwright-report ID
59 id: playwright-report-artifact-id
60 env:
61 ARTIFACTS_JSON: ${{ steps.playwright-report.outputs.artifacts }}
62 run: |
63 ID=$(echo "$ARTIFACTS_JSON" | jq -r '.[0].id');
64 echo "id=$ID" >> "$GITHUB_OUTPUT"
65
66 - name: Load artifacts into environment variables
67 id: playwright
68 run: |
69 EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
70 {
71 echo "PLAYWRIGHT_OUTPUT<<$EOF";
72 cat ./playwright-output;
73 echo "$EOF";
74 echo "MASTER_SCREENSHOTS_OUTCOME<<$EOF";
75 [ -f ./master-screenshots-outcome ] && cat ./master-screenshots-outcome;
76 echo "$EOF";
77 echo "FAILED=$(jq -r '.stats.unexpected' playwright-results.json)";
78 echo "FLAKY=$(jq -r '.stats.flaky' playwright-results.json)";
79 } >> "$GITHUB_OUTPUT"
80
81 # this is required because github.event.workflow_run.pull_requests is not available for PRs from forks
82 - name: Get PR context
83 id: source-run-info
84 env:
85 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86 # Find the most recently updated open PR at the repo with the requested commit:
87 SEARCH_QUERY: >-
88 type:pr state:open sort:updated-desc
89 repo:${{ github.repository }}
90 ${{ github.event.workflow_run.head_sha }}
91 # Minimal graphql search query to fetch the PR `number` field:
92 GQL: |-
93 query($filter: String!) {
94 search( query: $filter, type: ISSUE, first: 1) {
95 nodes { ... on PullRequest { number } }
96 }
97 }
98 # Formats the GQL response into a `key=value` string + basic error handling
99 JQ_FILTER: >-
100 .data.search.nodes[0]
101 | if (.number == null) then error("Could not find PR number") end
102 | "pullRequestNumber=\(.number)"
103 run: |
104 gh api graphql --field "filter=$SEARCH_QUERY" --raw-field "query=$GQL" --jq "$JQ_FILTER" >> "${GITHUB_OUTPUT}"
105
106 - name: "[Comment] Couldn't download screenshots from master branch"
107 uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
108 if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME == 'failure'
109 with:
110 issue: ${{ steps.source-run-info.outputs.pullRequestNumber }}
111 message: |
112 :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.
113
114 - name: "[Comment] Warning: Visual differences caused by this PR; please check the playwright report"
115 uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
116 if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME != 'failure' && steps.playwright.outputs.FAILED != 0
117 with:
118 issue: ${{ steps.source-run-info.outputs.pullRequestNumber }}
119 message: |
120 :warning: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${{ steps.playwright-report-artifact-id.outputs.id }}">Visual changes detected by playwright; please check the report to verify if they are desirable.</a>
121
122 - name: "[Comment] Success (but flaky): No visual differences introduced by this PR (but flaky tests detected)"
123 uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
124 if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME != 'failure' && steps.playwright.outputs.FLAKY != 0 && steps.playwright.outputs.FAILED == 0
125 with:
126 issue: ${{ steps.source-run-info.outputs.pullRequestNumber }}
127 message: |
128 :heavy_check_mark: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${{ steps.playwright-report-artifact-id.outputs.id }}">No visual changes detected by playwright, but flaky tests were detected; please try to fix the tests.</a>
129
130 - name: "[Comment] Success: No visual differences introduced by this PR"
131 uses: mshick/add-pr-comment@b8f338c590a895d50bcbfa6c5859251edc8952fc # v2.8.2
132 if: steps.playwright.outputs.MASTER_SCREENSHOTS_OUTCOME != 'failure' && steps.playwright.outputs.FLAKY == 0 && steps.playwright.outputs.FAILED == 0
133 with:
134 issue: ${{ steps.source-run-info.outputs.pullRequestNumber }}
135 message: |
136 :heavy_check_mark: <a href="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}/artifacts/${{ steps.playwright-report-artifact-id.outputs.id }}">No visual changes detected by playwright.</a>
137 update-only: true