From a741fa1e168f6d79c19b49175baeeb60f824235a44b3aae0f1aa3b78d282ff67 Mon Sep 17 00:00:00 2001 From: ahdoawhfo Date: Fri, 17 Apr 2026 13:51:08 +0800 Subject: [PATCH] Make toolchain install resilient to apt outages Only install tools that are actually missing (gitea/runner-images already ships curl/jq/tar), and point apt at mirrors.aliyun.com when we do need to install something so archive.ubuntu.com timeouts stop blocking the build. Handles both Noble's DEB822 ubuntu.sources and the legacy sources.list. Co-Authored-By: Claude Opus 4.7 (1M context) --- .gitea/workflows/release.yml | 42 +++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index f60f8bc..9f40bd6 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -45,17 +45,53 @@ jobs: with: fetch-depth: 0 - - name: Install toolchain + - name: Install toolchain (only what's missing) run: | set -euo pipefail + + MISSING=() + for tool in shellcheck jq curl tar sha256sum; do + command -v "$tool" >/dev/null 2>&1 || MISSING+=("$tool") + done + + if [[ ${#MISSING[@]} -eq 0 ]]; then + echo "所有工具已就绪,跳过安装。" + exit 0 + fi + echo "需要安装: ${MISSING[*]}" + if [[ $EUID -ne 0 ]] && command -v sudo >/dev/null 2>&1; then SUDO=sudo else SUDO= fi + + # 切换到阿里云镜像以避开 archive.ubuntu.com / security.ubuntu.com 出境超时。 + if [[ -f /etc/apt/sources.list.d/ubuntu.sources ]]; then + $SUDO sed -i \ + -e 's|http://archive.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' \ + -e 's|http://security.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' \ + /etc/apt/sources.list.d/ubuntu.sources + fi + if [[ -f /etc/apt/sources.list ]]; then + $SUDO sed -i \ + -e 's|http://archive.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' \ + -e 's|http://security.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' \ + /etc/apt/sources.list + fi + + # 实际安装的包名映射(coreutils 提供 sha256sum)。 + PKGS=() + for tool in "${MISSING[@]}"; do + case "$tool" in + sha256sum) PKGS+=(coreutils) ;; + *) PKGS+=("$tool") ;; + esac + done + $SUDO apt-get update -qq - DEBIAN_FRONTEND=noninteractive $SUDO apt-get install -y -qq \ - shellcheck jq curl tar coreutils ca-certificates + DEBIAN_FRONTEND=noninteractive $SUDO apt-get install -y -qq --no-install-recommends \ + "${PKGS[@]}" ca-certificates - name: Run shellcheck run: |