From faeb9c03bb95cd47fa07336b7099ffd7de2cff55 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:44:06 -0800 Subject: [PATCH] Fix: fall back to Ubuntu mirrors after the first apt failure Co-Authored-By: Codex <267193182+codex@users.noreply.github.com> --- .github/actions/apt-install/action.yml | 2 +- .github/actions/apt-install/install.sh | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/actions/apt-install/action.yml b/.github/actions/apt-install/action.yml index 5915e73166..2a3c651816 100644 --- a/.github/actions/apt-install/action.yml +++ b/.github/actions/apt-install/action.yml @@ -1,6 +1,6 @@ name: Install apt packages description: > - Installs apt packages using Ubuntu mirrors and bounded download retries. Caches downloaded packages as an optimization; apt resolves dependencies on every run. + Installs apt packages with bounded download retries and Ubuntu mirror fallback. Caches downloaded packages as an optimization; apt resolves dependencies on every run. inputs: packages: diff --git a/.github/actions/apt-install/install.sh b/.github/actions/apt-install/install.sh index ae908f4128..11447785f3 100644 --- a/.github/actions/apt-install/install.sh +++ b/.github/actions/apt-install/install.sh @@ -19,16 +19,18 @@ read -r -a requested_packages <<< "$PACKAGES" mkdir -p "$CACHE_DIR" touch "$CACHE_DIR/.keep" -# Hosted runners use a mirror list; job containers can point directly at Azure. -# Handle both layouts, leaving other repositories and signature checks intact. -if [ -f /etc/apt/apt-mirrors.txt ]; then - "${SUDO[@]}" sed -i '\|azure\.archive\.ubuntu\.com|d' /etc/apt/apt-mirrors.txt -fi -for source in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do - if [ -f "$source" ]; then - "${SUDO[@]}" sed -i 's|azure\.archive\.ubuntu\.com|archive.ubuntu.com|g' "$source" +use_ubuntu_mirrors() { + # Hosted runners use a mirror list; job containers can point directly at Azure. + # Handle both layouts, leaving other repositories and signature checks intact. + if [ -f /etc/apt/apt-mirrors.txt ]; then + "${SUDO[@]}" sed -i '\|azure\.archive\.ubuntu\.com|d' /etc/apt/apt-mirrors.txt fi -done + for source in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do + if [ -f "$source" ]; then + "${SUDO[@]}" sed -i 's|azure\.archive\.ubuntu\.com|archive.ubuntu.com|g' "$source" + fi + done +} for attempt in $(seq 1 "$ATTEMPTS"); do echo "::group::apt download attempt ${attempt}/${ATTEMPTS}" @@ -43,6 +45,10 @@ for attempt in $(seq 1 "$ATTEMPTS"); do fi echo "::endgroup::" echo "::warning::apt download attempt ${attempt}/${ATTEMPTS} failed or exceeded ${ATTEMPT_TIMEOUT}s" + if [ "$attempt" -eq 1 ] && [ "$ATTEMPTS" -gt 1 ]; then + echo "Switching from Azure to Ubuntu archive mirrors for remaining attempts" + use_ubuntu_mirrors + fi done echo "::error::apt download failed after ${ATTEMPTS} attempts"