diff --git a/scripts/publish-gitea-release.sh b/scripts/publish-gitea-release.sh index fde3288..27e95e7 100755 --- a/scripts/publish-gitea-release.sh +++ b/scripts/publish-gitea-release.sh @@ -110,8 +110,18 @@ require_cmd() { command -v "$1" >/dev/null 2>&1 || fail "缺少命令:$1" } +detect_python() { + if command -v python3 >/dev/null 2>&1; then + echo "python3" + elif command -v python >/dev/null 2>&1; then + echo "python" + else + return 1 + fi +} + json_escape() { - python -c 'import json,sys; print(json.dumps(sys.stdin.read()))' + "$PYTHON_BIN" -c 'import json,sys; print(json.dumps(sys.stdin.read()))' } api_url() { @@ -131,7 +141,7 @@ api_post_json() { } release_id_from_json() { - python -c 'import json,sys; print(json.load(sys.stdin)["id"])' + "$PYTHON_BIN" -c 'import json,sys; print(json.load(sys.stdin)["id"])' } [[ -n "$TAG" ]] || fail "必须指定 --tag" @@ -141,7 +151,7 @@ release_id_from_json() { require_cmd curl require_cmd git -require_cmd python +PYTHON_BIN="$(detect_python)" || fail "缺少命令:python 或 python3" for package in "${PACKAGES[@]}"; do [[ -f "$package" ]] || fail "发布包不存在:$package"