aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/playwright.yml
blob: be3e2c19fb5ab02a92881703d6043fd3e25be231 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Playwright Tests
on:
  push:
    branches: [master]
  pull_request:
permissions:
  contents: read
jobs:
  playwright:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    steps:
      - name: Remove all fonts
        run: rm -rf /usr/share/fonts

      - uses: actions/checkout@v4

      - name: Install CJK fonts
        uses: awalsh128/cache-apt-pkgs-action@1850ee53f6e706525805321a3f2f863dcf73c962 # v1.3.0
        with:
          packages: fonts-ipafont-mincho
          execute_install_scripts: true

      - uses: actions/setup-node@v3
        with:
          cache: "npm"
          node-version-file: ".node-version"

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Cache playwright browsers
        id: cache-playwright
        uses: actions/cache@v3
        with:
          path: |
            ~/.cache/ms-playwright
          key: cache-playwright-${{ hashFiles('package-lock.json') }} # playwright version is included in package-lock, so this serves as a reasonable cache key

      - if: ${{ steps.cache-playwright.outputs.cache-hit != 'true' }}
        name: Install Playwright Browsers
        run: npx playwright install chromium

      - name: Grab latest dictionaries from dictionaries branch
        uses: actions/checkout@v4
        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@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e # pin@v2
        continue-on-error: true
        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
          workflow_conclusion: success
          path: test/playwright/__screenshots__/

      - name: "[PR] Generate new screenshots & compare against master"
        id: playwright
        env:
          PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS: 1
        run: |
          npx playwright test 2>&1 | tee ./playwright-output || true
        continue-on-error: true
        if: github.event_name == 'pull_request' && steps.master-screenshots.outcome != 'failure'

      - name: "[Push] Generate new authoritative screenshots for master"
        id: playwright-master
        run: npx playwright test -u
        if: github.event_name == 'push'

      - uses: actions/upload-artifact@v3
        with:
          name: playwright-screenshots
          path: test/playwright/__screenshots__/

      - uses: actions/upload-artifact@v3
        with:
          name: playwright-report
          path: playwright-report/

      - 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'

      - uses: actions/upload-artifact@v3
        with:
          name: master-screenshots-outcome
          path: master-screenshots-outcome
        if: github.event_name == 'pull_request'

      - uses: actions/upload-artifact@v3
        with:
          name: playwright-output
          path: playwright-output
        if: github.event_name == 'pull_request'