[cli-release-discovery][iter-1] fix(install): select stable CLI releases and verify platform assets
Installer Tests / bash-discovery (pull_request) Successful in 1s
Installer Tests / powershell-discovery (pull_request) Successful in 8s

这个提交包含在:
朱四宏
2026-11-14 22:26:21 +08:00
父节点 fca5e79658
当前提交 796948d384
共修改 7 个文件,包含 396 行新增和 41 行删除
+120 -3
查看文件
@@ -28,6 +28,125 @@ Examples:
EOF
}
# Parse release JSON without adding a jq/python/node dependency to curl | bash.
# Return the first public stable CLI release in API order, never a desktop tag.
# Exit 3 means this page contains no eligible release; an empty page ends paging.
select_cli_release() {
LC_ALL=C awk -v asset="$1" '
function fail() { invalid = 1; exit 2 }
function ws() { while (substr(json, pos, 1) ~ /[ \t\r\n]/ && pos <= length(json)) pos++ }
function string( out,c,e,h,n,i,d) {
if (substr(json,pos++,1) != "\"") fail()
out = ""
while (pos <= length(json)) {
c = substr(json,pos++,1)
if (c == "\"") return out
if (c ~ /[[:cntrl:]]/) fail()
if (c == "\\") {
e = substr(json,pos++,1)
if (e == "\"" || e == "\\" || e == "/") c = e
else if (e == "b") c = sprintf("%c",8)
else if (e == "f") c = sprintf("%c",12)
else if (e == "n") c = "\n"
else if (e == "r") c = "\r"
else if (e == "t") c = "\t"
else if (e == "u") {
h = substr(json,pos,4)
if (length(h) != 4 || h ~ /[^0-9a-fA-F]/) fail()
pos += 4; n = 0
for (i=1;i<=4;i++) { d=index("0123456789abcdef",tolower(substr(h,i,1)))-1; n=n*16+d }
# Selection fields are ASCII; non-ASCII never match CLI names.
c = n > 0 && n < 128 ? sprintf("%c",n) : "?"
} else fail()
}
out = out c
}
fail()
}
function parse(path,depth, c,key,child,n,token) {
if (depth > 64) fail()
ws(); c=substr(json,pos,1)
if (c == "{" || c == "[") {
kind[path] = c == "{" ? "object" : "array"
pos++; ws(); n=0
if (substr(json,pos,1) == (c == "{" ? "}" : "]")) { pos++; count[path]=0; return }
while (1) {
if (c == "{") {
ws(); key=string(); ws()
if (substr(json,pos++,1) != ":") fail()
gsub(/%/,"%25",key); gsub(/\//,"%2F",key)
} else key=n
child=path "/" key
if (child in kind) fail()
parse(child,depth+1); n++; ws()
token=substr(json,pos++,1)
if (token == (c == "{" ? "}" : "]")) break
if (token != ",") fail()
}
count[path]=n
} else if (c == "\"") { kind[path]="string"; value[path]=string() }
else {
token=substr(json,pos)
if (match(token,/^(true|false|null)/)) {
value[path]=substr(token,1,RLENGTH); kind[path]="literal"; pos+=RLENGTH
} else if (match(token,/^-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/)) {
value[path]=substr(token,1,RLENGTH); kind[path]="number"; pos+=RLENGTH
} else fail()
}
}
{ json = json $0 "\n" }
END {
if (invalid) exit 2
pos=1; parse("",0); ws()
if (pos <= length(json) || kind[""] != "array") exit 2
if (count[""] == 0) { print "END"; exit 0 }
for (i=0;i<count[""];i++) {
p="/" i
if (kind[p] != "object") exit 2
if (kind[p "/tag_name"] != "string" || value[p "/tag_name"] !~ /^v[0-9]+\.[0-9]+\.[0-9]+$/) continue
if (kind[p "/draft"] != "literal" || value[p "/draft"] != "false") continue
if (kind[p "/prerelease"] != "literal" || value[p "/prerelease"] != "false") continue
if (kind[p "/assets"] == "array") {
for (j=0;j<count[p "/assets"];j++) {
a=p "/assets/" j "/name"
if (kind[a] == "string" && value[a] == asset) {
print substr(value[p "/tag_name"],2); exit 0
}
}
}
# Do not silently downgrade when the newest CLI release is incomplete.
exit 4
}
exit 3
}'
}
get_latest_cli_version() {
local page releases result status
for ((page=1; page<=100; page++)); do
if ! releases=$(curl -fsSL --connect-timeout 10 --max-time 30 "${GITEA_API_URL:-https://eightarms.net/api/v1}/repos/Octopus/octopus-release/releases?limit=50&page=$page"); then
echo "Error: Failed to fetch CLI releases (page $page)." >&2
return 1
fi
if result=$(printf '%s' "$releases" | select_cli_release "$1"); then
if [ "$result" = "END" ]; then break; fi
printf '%s\n' "$result"
return 0
else
status=$?
if [ "$status" = 3 ]; then continue; fi
if [ "$status" = 4 ]; then
echo "Error: Latest stable CLI release is missing platform asset $1." >&2
else
echo "Error: Invalid CLI release metadata." >&2
fi
return 1
fi
done
echo "Error: No public stable CLI release found within 100 pages." >&2
return 1
}
requested_version=${VERSION:-}
no_modify_path=false
binary_path=""
@@ -183,9 +302,7 @@ else
fi
if [ -z "$requested_version" ]; then
specific_version=$(curl -s "${GITEA_API_URL:-https://eightarms.net/api/v1}/repos/Octopus/octopus-release/releases?limit=1" | sed -n 's/.*"tag_name": *"v\([^"]*\)".*/\1/p')
if [[ $? -ne 0 || -z "$specific_version" ]]; then
if ! specific_version=$(get_latest_cli_version "$filename"); then
echo -e "${RED}Failed to fetch version information${NC}"
exit 1
fi