mirror of
https://github.com/nexu-io/open-design.git
synced 2026-09-20 06:15:06 +08:00
e3ac55baf7
* fix(ci): pin Blacksmith apt mirror before Playwright deps install * ci: retrigger on blacksmith runner mode
128 lines
5.2 KiB
YAML
128 lines
5.2 KiB
YAML
name: Setup Playwright
|
|
description: Use a preseeded Nexu browser when available, otherwise restore the 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 preinstalled Playwright
|
|
id: preinstalled-playwright
|
|
shell: bash
|
|
env:
|
|
RUNNER_LABELS_JSON: ${{ inputs.runner-labels }}
|
|
run: |
|
|
preinstalled_enabled=false
|
|
|
|
# The ARC tools image carries both the OS dependencies and Chromium.
|
|
# Keep this opt-in to the named Nexu profiles so a hosted runner with
|
|
# a restored browser cache still receives its OS dependencies.
|
|
case "$RUNNER_LABELS_JSON" in
|
|
*'"nexu-runners-'*)
|
|
if [ -n "${PLAYWRIGHT_BROWSERS_PATH:-}" ] && [ -d "$PLAYWRIGHT_BROWSERS_PATH" ]; then
|
|
chromium_bin="$(find "$PLAYWRIGHT_BROWSERS_PATH" -type f \
|
|
\( -name chrome -o -name chromium -o -name chrome-headless-shell \) \
|
|
-perm -111 -print -quit 2>/dev/null || true)"
|
|
if [ -n "$chromium_bin" ]; then
|
|
preinstalled_enabled=true
|
|
fi
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
echo "enabled=$preinstalled_enabled" >> "$GITHUB_OUTPUT"
|
|
if [ "$preinstalled_enabled" = "true" ]; then
|
|
echo "Using the Playwright browser preseeded in the Nexu runner image."
|
|
else
|
|
echo "No preseeded Playwright browser detected; using the workflow install path."
|
|
fi
|
|
|
|
- name: Detect persistent Playwright cache
|
|
id: persistent-playwright-cache
|
|
if: ${{ steps.preinstalled-playwright.outputs.enabled != 'true' }}
|
|
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
|
|
if: ${{ steps.preinstalled-playwright.outputs.enabled != 'true' }}
|
|
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.preinstalled-playwright.outputs.enabled != 'true' && 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: Ensure preinstalled Playwright browser revision
|
|
if: ${{ steps.preinstalled-playwright.outputs.enabled == 'true' }}
|
|
shell: bash
|
|
env:
|
|
PACKAGE_JSON_PATH: ${{ inputs.package-json-path }}
|
|
run: |
|
|
package_dir="${PACKAGE_JSON_PATH%/*}"
|
|
pnpm -C "$package_dir" exec playwright install chromium
|
|
|
|
- name: Pin Blacksmith apt mirror to the canonical archive
|
|
if: ${{ steps.preinstalled-playwright.outputs.enabled != 'true' }}
|
|
shell: bash
|
|
env:
|
|
RUNNER_LABELS_JSON: ${{ inputs.runner-labels }}
|
|
run: |
|
|
# Blacksmith VMs resolve apt through a mirrorlist of third-party
|
|
# university mirrors. When one goes down, apt retries it for every
|
|
# index file before falling back, so the `apt-get update` inside
|
|
# `playwright install --with-deps` hangs until the job timeout.
|
|
# Browser OS deps are NOT fully preinstalled on the Blacksmith image
|
|
# (xvfb, fonts, libasound are missing), so apt must stay in the path;
|
|
# pin the canonical archive so it stays deterministic instead.
|
|
case "$RUNNER_LABELS_JSON" in
|
|
*'"blacksmith-'*) ;;
|
|
*) exit 0 ;;
|
|
esac
|
|
mirrorlist=/etc/apt/blacksmith-ubuntu-mirrors.txt
|
|
if [ -f "$mirrorlist" ]; then
|
|
printf 'http://archive.ubuntu.com/ubuntu\tpriority:1\n' | sudo tee "$mirrorlist"
|
|
fi
|
|
|
|
- name: Install Playwright browsers
|
|
if: ${{ steps.preinstalled-playwright.outputs.enabled != 'true' }}
|
|
shell: bash
|
|
run: ${{ inputs.install-command }}
|