From 53f33b55d1313f2f149b62e8a445f66a57fdef14 Mon Sep 17 00:00:00 2001 From: chuan Date: Sat, 9 May 2026 23:09:43 +0800 Subject: [PATCH] ci: rewrite all ubuntu apt sources --- .github/workflows/release.yml | 39 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6bbfe83..89f5220 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -139,15 +139,36 @@ jobs: run: | set -euo pipefail - if command -v sudo >/dev/null 2>&1; then - sudo sed -i 's|http://archive.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g; s|http://security.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g' /etc/apt/sources.list - sudo apt-get update - sudo apt-get install -y --no-install-recommends binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64-posix mingw-w64-x86-64-dev - else - sed -i 's|http://archive.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g; s|http://security.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g' /etc/apt/sources.list - apt-get update - apt-get install -y --no-install-recommends binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64-posix mingw-w64-x86-64-dev - fi + apt_run() { + if command -v sudo >/dev/null 2>&1; then + sudo "$@" + else + "$@" + fi + } + + rewrite_apt_sources() { + local files=() + [[ -f /etc/apt/sources.list ]] && files+=(/etc/apt/sources.list) + while IFS= read -r file; do + files+=("${file}") + done < <(find /etc/apt/sources.list.d -type f \( -name "*.list" -o -name "*.sources" \) 2>/dev/null) + + if [[ "${#files[@]}" -gt 0 ]]; then + apt_run sed -i \ + -e 's|http://archive.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g' \ + -e 's|https://archive.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g' \ + -e 's|http://security.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g' \ + -e 's|https://security.ubuntu.com/ubuntu|https://mirrors.tuna.tsinghua.edu.cn/ubuntu|g' \ + -e 's|http://ports.ubuntu.com/ubuntu-ports|https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports|g' \ + -e 's|https://ports.ubuntu.com/ubuntu-ports|https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports|g' \ + "${files[@]}" + fi + } + + rewrite_apt_sources + apt_run apt-get update + apt_run apt-get install -y --no-install-recommends binutils-mingw-w64-x86-64 gcc-mingw-w64-x86-64-posix mingw-w64-x86-64-dev rustup target add x86_64-pc-windows-gnu - name: Build Windows x64