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"