From f839ea2266fc4889513193f77ba6fbe11fe794dd Mon Sep 17 00:00:00 2001 From: zhilv Date: Mon, 25 May 2026 22:41:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(workflow):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=8F=91=E5=B8=83=E6=9E=84=E5=BB=BA=E7=9A=84=20Rust?= =?UTF-8?q?=20=E7=9B=AE=E6=A0=87=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 安装和构建阶段优先使用系统 rustc/cargo,避免被 ~/.cargo/bin 中的 musl 工具链覆盖 - 仅在系统工具链缺失时才加载或安装 rustup,减少 runner 现有环境带来的干扰 - 当使用 rustup 时自动补齐 x86_64-unknown-linux-gnu target,匹配发布脚本的构建目标 --- .gitea/workflows/release.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index d37c545..872a152 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -60,14 +60,17 @@ jobs: - name: 安装 Rust run: | set -eux - if [ -f "$HOME/.cargo/env" ]; then - . "$HOME/.cargo/env" + PATH_WITHOUT_CARGO_BIN="$(printf '%s' "$PATH" | awk -v RS=: -v ORS=: '$0 != ENVIRON["HOME"] \"/.cargo/bin\" { print }' | sed 's/:$//')" + export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${PATH_WITHOUT_CARGO_BIN:+:$PATH_WITHOUT_CARGO_BIN}" + if ! command -v cargo >/dev/null 2>&1 || ! command -v rustc >/dev/null 2>&1; then + [ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env" fi - export PATH="$HOME/.cargo/bin:$PATH" - if ! command -v cargo >/dev/null 2>&1; then + if ! command -v cargo >/dev/null 2>&1 || ! command -v rustc >/dev/null 2>&1; then curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal . "$HOME/.cargo/env" - export PATH="$HOME/.cargo/bin:$PATH" + fi + if command -v rustup >/dev/null 2>&1; then + rustup target list --installed | grep -qx 'x86_64-unknown-linux-gnu' || rustup target add x86_64-unknown-linux-gnu fi rustc -V cargo -V @@ -75,7 +78,11 @@ jobs: - name: 构建发布包 run: | set -eux - . "$HOME/.cargo/env" 2>/dev/null || true + PATH_WITHOUT_CARGO_BIN="$(printf '%s' "$PATH" | awk -v RS=: -v ORS=: '$0 != ENVIRON["HOME"] \"/.cargo/bin\" { print }' | sed 's/:$//')" + export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin${PATH_WITHOUT_CARGO_BIN:+:$PATH_WITHOUT_CARGO_BIN}" + if ! command -v cargo >/dev/null 2>&1 || ! command -v rustc >/dev/null 2>&1; then + [ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env" + fi cd lightops-src TAG="$(cat /tmp/lightops-release-tag)" VERSION="${TAG#v}"