diff --git a/.github/scripts/install-playwright.sh b/.github/scripts/install-playwright.sh index ca41f793469..6ca4abd22a2 100644 --- a/.github/scripts/install-playwright.sh +++ b/.github/scripts/install-playwright.sh @@ -25,11 +25,28 @@ deps_present() { # dpkg, not apt: apt prefers a repository copy of a package whose version matches a cached file # and fetches it. The cache key pins the runner image, so the files are the exact set apt # installed there, and dpkg resolves their dependencies among themselves without the network. +# Removes the archives dpkg names under "Errors were encountered while processing:" (a .deb path +# or a package name), so the cache keeps every file that installed and loses only those that failed. +drop_failed_archives() { + local entry + printf '%s\n' "$1" | sed -n '/^Errors were encountered while processing:/,$p' | tail -n +2 | + sed 's/^[[:space:]]*//' | while IFS= read -r entry; do + case "$entry" in + *.deb) rm -f "$entry" ;; + ?*) rm -f "$cache/${entry%%:*}"_*.deb ;; + esac + done +} + install_from_cache() { [ -n "$cache" ] && compgen -G "$cache/*.deb" > /dev/null || return 1 + # Snap transitional packages (Ubuntu's firefox, for one) install snapd and fail offline; a + # cache saved before they were excluded still carries them. + rm -f "$cache"/*snap*.deb local output if ! output=$(sudo DEBIAN_FRONTEND=noninteractive dpkg -i "$cache"/*.deb 2>&1); then printf '%s\n' "$output" | tail -n 5 | sed 's/^/Cache install failed: /' + drop_failed_archives "$output" dpkg_failed=true return 1 fi @@ -50,7 +67,7 @@ if ! deps_present; then bunx --no-install playwright install-deps "${browsers[@]}" if [ -n "$cache" ] && compgen -G '/var/cache/apt/archives/*.deb' > /dev/null; then mkdir -p "$cache" - cp /var/cache/apt/archives/*.deb "$cache"/ + find /var/cache/apt/archives -maxdepth 1 -name '*.deb' ! -name '*snap*' -exec cp {} "$cache"/ \; touch "$cache/.updated" echo "Stored $(find "$cache" -name '*.deb' | wc -l) packages in $cache" elif [ -n "$cache" ]; then