1
0
forked from Eeveid/lightOps

🐛 fix(release): 去除发布脚本对 Python 的硬依赖

- 发布脚本优先使用 node 处理 JSON,没有 node 时再回退到 python3 或 python
- 修复 runner 缺少 Python 解释器时 Release 创建阶段直接失败的问题
- 保持现有 Gitea API 调用和附件上传流程不变
This commit is contained in:
2026-05-26 11:12:16 +08:00
parent 57447882cb
commit 100909a47f

View File

@@ -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"