LoginSignup
0
0

PlaywrightのDocker imageとactions/cache

Posted at

Github Actions上で動くPlaywrightを少しでも早くするために、ブラウザを毎回インストールする方法からDocker imageを使う方法に変更しました。
imageのバージョンはpackage.jsonに記載しているバージョンと同じものにします。

(色々あってライブラリのインストールとテスト実行は別々のジョブにしている)

jobs:
  setup:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Cache node modules
      uses: actions/cache@v4
      id: cache-node-modules
      with:
        path: node_modules
        key: node_modules-${{ hashFiles('yarn.lock') }}
        restore-keys: node_modules-
    - name: Install dependencies
      if: steps.cache-node-modules.outputs.cache-hit != 'true'
      run: yarn install --frozen-lockfile

    test:
        needs: setup
+       container: mcr.microsoft.com/playwright:v1.43.1-jammy
        runs-on: ubuntu-latest
        steps:
        - uses: actions/checkout@v4
          with:
            fetch-depth: 0
        - name: Get node modules
          uses: actions/cache/restore@v4
          with:
            path: node_modules
            key: node_modules-${{ hashFiles('yarn.lock') }}
            restore-keys: node_modules-
        - name: Run Playwright tests
          run: |
            CI=true yarn run test

なぜかキャッシュが見つからない

いざ実行するとキャッシュが見つからずコケてしまった…

Run actions/cache/restore@v4
  with:
    path: node_modules
    key: node_modules-xxxx
    restore-keys: node_modules-
    enableCrossOsArchive: false
    fail-on-cache-miss: false
    lookup-only: false
/usr/bin/docker exec  xxxxxx sh -c "cat /etc/*release | grep ^ID"
Cache not found for input keys: node_modules-xxxx, node_modules-

別のジョブではキャッシュを取得できたので、キャッシュはあるもののコンテナ内からなぜか取得できていない様子。

解決策

Playwrightとactions/cache両方のissueを読み漁ってやっと問題にたどり着きました。

actions/cacheではzstdが必須だが、PlaywrightのDocker imageには含まれていなかったのが原因でした。

ということでzstdをインストールするstepを追加して解決。

 test:
        needs: setup
        container: mcr.microsoft.com/playwright:v1.43.1-jammy
        runs-on: ubuntu-latest
        steps:
+       - name: Install zstd
+         run: |
+           apt-get update
+           apt-get install zstd
        - uses: actions/checkout@v4
          with:
            fetch-depth: 0
        - name: Get node modules
          uses: actions/cache/restore@v4
          with:
            path: node_modules
            key: node_modules-${{ hashFiles('yarn.lock') }}
            restore-keys: node_modules-
        - name: Run Playwright tests
          run: |
            CI=true yarn run test

インストールする分若干時間が延びてしまいますが、これでnpx playwright install --with-depsを実行するより大幅に短縮できました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0