aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-03-26 22:21:19 +0900
committerGitHub <noreply@github.com>2023-03-26 22:21:19 +0900
commit1421c4ec7a864281c3aad9803cf029ecc4296db8 (patch)
tree04fd42207509f48c01b7a038ee9b7c6117d4f530 /.github/workflows
parent9a41d65edaabc938c74e69f4dee4098c35a1e05b (diff)
parent8f64cc4ba7a32917e82adbefa7dd4526edd011ed (diff)
Merge pull request #108 from themoeway/fix-playwright-action
Fix playwright action so that it leaves comments even for PRs from forks
Diffstat (limited to '.github/workflows')
-rw-r--r--.github/workflows/playwright.yml50
-rw-r--r--.github/workflows/playwright_comment.yml72
2 files changed, 88 insertions, 34 deletions
diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml
index 5ee786ef..409d73a6 100644
--- a/.github/workflows/playwright.yml
+++ b/.github/workflows/playwright.yml
@@ -9,9 +9,6 @@ jobs:
playwright:
timeout-minutes: 60
runs-on: ubuntu-latest
- permissions:
- pull-requests: write
- contents: write
steps:
- uses: actions/checkout@v3
@@ -38,15 +35,17 @@ jobs:
- name: Grab latest dictionaries from dictionaries branch
uses: actions/checkout@v3
with:
+ repository: themoeway/yomitan # so that this works on forks
ref: dictionaries
path: dictionaries
- name: Grab latest screenshots from master branch
uses: dawidd6/action-download-artifact@5e780fc7bbd0cac69fc73271ed86edf5dcb72d67 # pin@v2
continue-on-error: true
- id: download-screenshots
+ id: master-screenshots
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
+ repo: themoeway/yomitan # so that this works on forks
name: playwright-screenshots
branch: master
workflow: playwright.yml
@@ -56,13 +55,9 @@ jobs:
- name: "[PR] Generate new screenshots & compare against master"
id: playwright
run: |
- EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
- echo "PLAYWRIGHT_OUTPUT<<$EOF" >> $GITHUB_OUTPUT
- npx playwright test 2>&1 | tee $GITHUB_OUTPUT || true
- echo "$EOF" >> $GITHUB_OUTPUT
- echo "NUM_FAILED=$(grep -c 'Screenshot comparison failed' $GITHUB_OUTPUT)" >> $GITHUB_OUTPUT
+ npx playwright test 2>&1 | tee ./playwright-output || true
continue-on-error: true
- if: github.event_name == 'pull_request' && steps.download-screenshots.outcome != 'failure'
+ if: github.event_name == 'pull_request' && steps.master-screenshots.outcome != 'failure'
- name: "[Push] Generate new authoritative screenshots for master"
id: playwright-master
@@ -79,31 +74,18 @@ jobs:
name: playwright-report
path: playwright-report/
- - name: "[Couldn't download screenshots] Comment results on PR"
- uses: mshick/add-pr-comment@a65df5f64fc741e91c59b8359a4bc56e57aaf5b1 # pin@v2
- if: github.event_name == 'pull_request' && steps.download-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 "download-screenshots" step in the workflow run and rerun it before merging.
+ - name: "[PR] Store steps.master-screenshots.outcome in a file"
+ run: echo ${{ steps.master-screenshots.outcome }} > ./master-screenshots-outcome
+ if: github.event_name == 'pull_request'
- - name: "[Success] Comment results on PR"
- uses: mshick/add-pr-comment@a65df5f64fc741e91c59b8359a4bc56e57aaf5b1 # pin@v2
- if: github.event_name == 'pull_request' && steps.download-screenshots.outcome != 'failure' && steps.playwright.outputs.NUM_FAILED == 0
+ - uses: actions/upload-artifact@v3
with:
- message: |
- :heavy_check_mark: No visual differences introduced by this PR.
- [View Playwright Report](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}#artifacts) (note: open the "playwright-report" artifact)
+ name: master-screenshots-outcome
+ path: master-screenshots-outcome
+ if: github.event_name == 'pull_request'
- - name: "[Failure] Comment results on PR"
- uses: mshick/add-pr-comment@a65df5f64fc741e91c59b8359a4bc56e57aaf5b1 # pin@v2
- if: github.event_name == 'pull_request' && steps.download-screenshots.outcome != 'failure' && steps.playwright.outputs.NUM_FAILED != 0
+ - uses: actions/upload-artifact@v3
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.run_id }}#artifacts) (note: open the "playwright-report" artifact)
+ name: playwright-output
+ path: playwright-output
+ if: github.event_name == 'pull_request'
diff --git a/.github/workflows/playwright_comment.yml b/.github/workflows/playwright_comment.yml
new file mode 100644
index 00000000..8c33b618
--- /dev/null
+++ b/.github/workflows/playwright_comment.yml
@@ -0,0 +1,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)