ci: probe Chromium binary, fall back to Playwright-bundled
Some checks failed
ci / build-test (push) Failing after 3m35s
Some checks failed
ci / build-test (push) Failing after 3m35s
The Ubuntu runner image ships /usr/bin/chromium-browser as a snap forwarder stub that exits with "install via snap" when invoked but is found on PATH. The previous detection used `command -v` only, so it accepted the stub, set CHROME_PATH to it, and Lighthouse later failed to launch Chrome (ECONNREFUSED on the debug port). Probe each candidate with `--version` to confirm it actually runs. When no working system binary exists, install Playwright's bundled Chromium (supports linux/arm64) with --with-deps for system libs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -36,39 +36,46 @@ jobs:
|
|||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
|
|
||||||
# Lighthouse CI needs a Chrome/Chromium binary at runtime. Google Chrome
|
# Lighthouse CI needs a Chrome/Chromium binary at runtime. Google Chrome
|
||||||
# has no Linux/arm64 build, so install distro Chromium and export its
|
# has no Linux/arm64 build, so we use distro Chromium when available and
|
||||||
# path. Handles both `chromium` (Debian) and `chromium-browser` (older
|
# fall back to Playwright's bundled Chromium (which supports linux/arm64)
|
||||||
# Ubuntu) package names, and works whether sudo is present or absent
|
# when not. The Ubuntu runner ships /usr/bin/chromium-browser as a snap
|
||||||
# (e.g. runner running as root).
|
# forwarder stub that is on PATH but only prints "install via snap" when
|
||||||
|
# invoked — so we MUST probe each candidate by actually running it,
|
||||||
|
# not just `command -v`.
|
||||||
- name: Install Chromium for Lighthouse CI
|
- name: Install Chromium for Lighthouse CI
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -e
|
set -euo pipefail
|
||||||
if command -v sudo >/dev/null 2>&1; then SUDO=sudo; else SUDO=; fi
|
|
||||||
|
|
||||||
resolve_chromium() {
|
probe() {
|
||||||
command -v chromium 2>/dev/null \
|
local bin="${1:-}"
|
||||||
|| command -v chromium-browser 2>/dev/null \
|
[ -n "$bin" ] && [ -x "$bin" ] && "$bin" --version >/dev/null 2>&1
|
||||||
|| true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHROME_BIN="$(resolve_chromium)"
|
CHROME_BIN=""
|
||||||
if [ -z "$CHROME_BIN" ]; then
|
for cand in \
|
||||||
$SUDO apt-get update -qq
|
"$(command -v chromium 2>/dev/null || true)" \
|
||||||
$SUDO apt-get install -y --no-install-recommends \
|
"$(command -v chromium-browser 2>/dev/null || true)" \
|
||||||
chromium chromium-driver \
|
"$(command -v google-chrome 2>/dev/null || true)"; do
|
||||||
|| $SUDO apt-get install -y --no-install-recommends \
|
if probe "$cand"; then CHROME_BIN="$cand"; break; fi
|
||||||
chromium-browser chromium-chromedriver
|
done
|
||||||
CHROME_BIN="$(resolve_chromium)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$CHROME_BIN" ]; then
|
if [ -z "$CHROME_BIN" ]; then
|
||||||
echo "Failed to install a Chromium binary — Lighthouse CI cannot run."
|
echo "No working system Chromium — installing Playwright-bundled Chromium."
|
||||||
|
# --with-deps apt-installs the system libraries Chromium needs
|
||||||
|
# (libnss3, libatk1.0-0, etc.). Playwright handles sudo internally.
|
||||||
|
npx -y playwright@latest install --with-deps chromium
|
||||||
|
CHROME_BIN="$(find "$HOME/.cache/ms-playwright" \
|
||||||
|
-type f -name chrome -executable 2>/dev/null | head -n1)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! probe "$CHROME_BIN"; then
|
||||||
|
echo "Failed to install a working Chromium binary." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "CHROME_PATH=$CHROME_BIN" >> "$GITHUB_ENV"
|
echo "CHROME_PATH=$CHROME_BIN" >> "$GITHUB_ENV"
|
||||||
"$CHROME_BIN" --version || true
|
"$CHROME_BIN" --version
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|||||||
Reference in New Issue
Block a user