From 100909a47fac92b19d01eb52448b0c270dcd899d Mon Sep 17 00:00:00 2001 From: zhilv Date: Tue, 26 May 2026 11:12:16 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(release):=20=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E5=8F=91=E5=B8=83=E8=84=9A=E6=9C=AC=E5=AF=B9=20Python?= =?UTF-8?q?=20=E7=9A=84=E7=A1=AC=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 发布脚本优先使用 node 处理 JSON,没有 node 时再回退到 python3 或 python - 修复 runner 缺少 Python 解释器时 Release 创建阶段直接失败的问题 - 保持现有 Gitea API 调用和附件上传流程不变 --- scripts/publish-gitea-release.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/publish-gitea-release.sh b/scripts/publish-gitea-release.sh index 27e95e7..42406d6 100755 --- a/scripts/publish-gitea-release.sh +++ b/scripts/publish-gitea-release.sh @@ -110,8 +110,10 @@ require_cmd() { command -v "$1" >/dev/null 2>&1 || fail "缺少命令:$1" } -detect_python() { - if command -v python3 >/dev/null 2>&1; then +detect_json_runtime() { + if command -v node >/dev/null 2>&1; then + echo "node" + elif command -v python3 >/dev/null 2>&1; then echo "python3" elif command -v python >/dev/null 2>&1; then echo "python" @@ -121,7 +123,14 @@ detect_python() { } json_escape() { - "$PYTHON_BIN" -c 'import json,sys; print(json.dumps(sys.stdin.read()))' + case "$JSON_RUNTIME" in + node) + node -e 'let s=""; process.stdin.setEncoding("utf8"); process.stdin.on("data", d => s += d); process.stdin.on("end", () => process.stdout.write(JSON.stringify(s)));' + ;; + *) + "$JSON_RUNTIME" -c 'import json,sys; print(json.dumps(sys.stdin.read()))' + ;; + esac } api_url() { @@ -141,7 +150,14 @@ api_post_json() { } release_id_from_json() { - "$PYTHON_BIN" -c 'import json,sys; print(json.load(sys.stdin)["id"])' + case "$JSON_RUNTIME" in + node) + node -e 'let s=""; process.stdin.setEncoding("utf8"); process.stdin.on("data", d => s += d); process.stdin.on("end", () => process.stdout.write(String(JSON.parse(s).id)));' + ;; + *) + "$JSON_RUNTIME" -c 'import json,sys; print(json.load(sys.stdin)["id"])' + ;; + esac } [[ -n "$TAG" ]] || fail "必须指定 --tag" @@ -151,7 +167,7 @@ release_id_from_json() { require_cmd curl require_cmd git -PYTHON_BIN="$(detect_python)" || fail "缺少命令:python 或 python3" +JSON_RUNTIME="$(detect_json_runtime)" || fail "缺少命令:node、python 或 python3" for package in "${PACKAGES[@]}"; do [[ -f "$package" ]] || fail "发布包不存在:$package"