From 292e42df67552efd355e3f1655cc60900d7604be Mon Sep 17 00:00:00 2001 From: sgash708 Date: Sat, 8 Aug 2026 19:29:53 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20Chrome=20for=20Testing=E3=81=A8action?= =?UTF-8?q?=E4=BE=9D=E5=AD=98=E3=82=92actions/cache=E3=81=A7=E3=82=AD?= =?UTF-8?q?=E3=83=A3=E3=83=83=E3=82=B7=E3=83=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit composite action内訳の実測(chromagic-demoでの計測): - Install Japanese fonts: 約11.3秒 - Setup Chrome for Testing: 約7.5秒 - Install action dependencies (npm ci): 約4秒 - Capture stories (storycap): 約7.2秒 browser-actions/setup-chromeはRUNNER_TOOL_CACHE配下にキャッシュする作りだが、 GitHub-hosted runnerは毎回使い捨てVMなのでジョブをまたいでは残らない。 actions/cache/restore+saveで永続化し、2回目以降のダウンロードをスキップする。 action自体のnode_modules(storycap等)もpackage-lock.jsonハッシュでキャッシュ。 Noto CJKフォントのキャッシュ化は、/usr/share/fonts配下がroot所有で actions/cacheの復元権限まわりの検証が必要なため今回は見送り(将来課題)。 --- action.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/action.yml b/action.yml index 32cdec7..a4789be 100644 --- a/action.yml +++ b/action.yml @@ -69,17 +69,50 @@ runs: sudo apt-get update sudo apt-get install -y --no-install-recommends fonts-noto-cjk + # browser-actions/setup-chrome は RUNNER_TOOL_CACHE 配下にキャッシュする作りだが、 + # GitHub-hosted runner は毎回使い捨て VM なのでジョブをまたいでは残らない。 + # actions/cache で永続化し、2回目以降のダウンロードをスキップする。 + - name: Restore Chrome for Testing cache + id: chrome-cache + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: ${{ runner.tool_cache }}/setup-chrome + key: chromagic-chrome-${{ runner.os }}-${{ runner.arch }} + - name: Setup Chrome for Testing id: chrome uses: browser-actions/setup-chrome@2e1d749697dd1612b833dba4a722266286fbefcd # v2 with: install-dependencies: true + - name: Save Chrome for Testing cache + if: ${{ steps.chrome-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: ${{ runner.tool_cache }}/setup-chrome + key: ${{ steps.chrome-cache.outputs.cache-primary-key }} + + # action 自体の node_modules(storycap 等)も package-lock.json のハッシュでキャッシュする。 + - name: Restore action dependencies cache + id: deps-cache + uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: ${{ github.action_path }}/node_modules + key: chromagic-deps-${{ runner.os }}-${{ hashFiles(format('{0}/package-lock.json', github.action_path)) }} + - name: Install action dependencies + if: ${{ steps.deps-cache.outputs.cache-hit != 'true' }} shell: bash # consumer 側は実行に要る依存だけ(devDeps=semantic-release 等は入れない)。 run: npm ci --prefix "$GITHUB_ACTION_PATH" --omit=dev --no-audit --no-fund + - name: Save action dependencies cache + if: ${{ steps.deps-cache.outputs.cache-hit != 'true' }} + uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: ${{ github.action_path }}/node_modules + key: ${{ steps.deps-cache.outputs.cache-primary-key }} + - name: Capture stories (storycap) shell: bash # inputs は run ブロックへ直接展開せず env 経由で渡す(shell/式インジェクション対策)。