Files
wehub-resource-sync 070959e133
landing-page-staging / Deploy landing page to staging (push) Has been skipped
landing-page-ci / Validate landing page (push) Failing after 4s
visual-baseline / Capture visual baselines (push) Has been cancelled
bake-plugin-previews / Bake plugin previews (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:00:47 +08:00

63 lines
2.2 KiB
YAML

name: Setup Playwright
description: Restore Playwright browser cache and install browsers
inputs:
package-json-path:
description: Path to package.json containing @playwright/test or playwright devDependency
required: true
install-command:
description: Command used to install browsers
required: true
runner-labels:
description: JSON array of labels selected for this job's runs-on value
required: false
default: '[]'
runs:
using: composite
steps:
- name: Detect persistent Playwright cache
id: persistent-playwright-cache
shell: bash
env:
RUNNER_LABELS_JSON: ${{ inputs.runner-labels }}
run: |
case "$RUNNER_LABELS_JSON" in
*'"od-persistent-ci"'*) persistent_enabled=true ;;
*) persistent_enabled=false ;;
esac
if [ "$persistent_enabled" = "true" ]; then
if [ -z "${PLAYWRIGHT_BROWSERS_PATH:-}" ]; then
echo "runner-labels contains od-persistent-ci, but PLAYWRIGHT_BROWSERS_PATH is not set" >&2
exit 1
fi
mkdir -p "$PLAYWRIGHT_BROWSERS_PATH"
echo "enabled=true" >> "$GITHUB_OUTPUT"
echo "path=$PLAYWRIGHT_BROWSERS_PATH" >> "$GITHUB_OUTPUT"
else
echo "enabled=false" >> "$GITHUB_OUTPUT"
fi
- name: Resolve Playwright version
id: playwright-version
shell: bash
run: |
version=$(node -p "const pkg = require('./${{ inputs.package-json-path }}'); const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) }; (deps['@playwright/test'] || deps.playwright || '').replace(/[^0-9.]/g,'')")
if [ -z "$version" ]; then
echo "Could not resolve Playwright version from ${{ inputs.package-json-path }}" >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Cache Playwright browser binaries
if: ${{ steps.persistent-playwright-cache.outputs.enabled != 'true' }}
uses: actions/cache@v5.0.5
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}
- name: Install Playwright browsers
shell: bash
run: ${{ inputs.install-command }}