Refactor release fetching and version checking logic (#7299)
This commit is contained in:
parent
c8d969d38a
commit
be255263c6
@ -1965,7 +1965,7 @@ check_for_gh_release() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Fetch releases (newest → oldest)
|
# Fetch releases (newest → oldest)
|
||||||
local releases=""
|
local releases
|
||||||
releases=$(
|
releases=$(
|
||||||
curl -fsSL --max-time 15 \
|
curl -fsSL --max-time 15 \
|
||||||
-H 'Accept: application/vnd.github+json' \
|
-H 'Accept: application/vnd.github+json' \
|
||||||
@ -1983,18 +1983,13 @@ check_for_gh_release() {
|
|||||||
local latest current
|
local latest current
|
||||||
latest=$(echo "$releases" | head -n1)
|
latest=$(echo "$releases" | head -n1)
|
||||||
current=""
|
current=""
|
||||||
if [[ -f "$current_file" ]]; then
|
[[ -f "$current_file" ]] && current="$(<"$current_file")"
|
||||||
current="$(<"$current_file")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Helper: get index of a version (lower = newer)
|
# Helper: get index of a version (lower = newer)
|
||||||
get_index() {
|
get_index() {
|
||||||
local ver="${1:-}"
|
local ver="${1:-}"
|
||||||
[[ -z "$ver" ]] && return 1
|
[[ -z "$ver" ]] && return 1
|
||||||
local idx
|
nl -ba <<<"$releases" | awk -v v="$ver" '$2==v{print $1; exit}'
|
||||||
idx=$(nl -ba <<<"$releases" | awk -v v="$ver" '$2==v{print $1; exit}')
|
|
||||||
[[ -n "$idx" ]] || return 1
|
|
||||||
echo "$idx"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Pinning enabled
|
# Pinning enabled
|
||||||
@ -2007,7 +2002,6 @@ check_for_gh_release() {
|
|||||||
if [[ -z "$current" ]]; then
|
if [[ -z "$current" ]]; then
|
||||||
msg_info "${app} pinned to v${pinned_version}, no local version → install required"
|
msg_info "${app} pinned to v${pinned_version}, no local version → install required"
|
||||||
CHECK_UPDATE_RELEASE="$pinned_version"
|
CHECK_UPDATE_RELEASE="$pinned_version"
|
||||||
touch "$current_file"
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -2027,14 +2021,12 @@ check_for_gh_release() {
|
|||||||
if [[ -z "$current_index" ]] || [[ "$current_index" -gt "$pinned_index" ]]; then
|
if [[ -z "$current_index" ]] || [[ "$current_index" -gt "$pinned_index" ]]; then
|
||||||
msg_info "${app} pinned to v${pinned_version} (installed v${current:-none}) → update required"
|
msg_info "${app} pinned to v${pinned_version} (installed v${current:-none}) → update required"
|
||||||
CHECK_UPDATE_RELEASE="$pinned_version"
|
CHECK_UPDATE_RELEASE="$pinned_version"
|
||||||
: >"$current_file"
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$current_index" -lt "$pinned_index" ]]; then
|
if [[ "$current_index" -lt "$pinned_index" ]]; then
|
||||||
msg_info "${app} pinned to v${pinned_version} (installed newer v${current}) → downgrade required"
|
msg_info "${app} pinned to v${pinned_version} (installed newer v${current}) → downgrade required"
|
||||||
CHECK_UPDATE_RELEASE="$pinned_version"
|
CHECK_UPDATE_RELEASE="$pinned_version"
|
||||||
: >"$current_file"
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -2045,7 +2037,6 @@ check_for_gh_release() {
|
|||||||
if [[ -z "$current" || "$current" != "$latest" ]]; then
|
if [[ -z "$current" || "$current" != "$latest" ]]; then
|
||||||
CHECK_UPDATE_RELEASE="$latest"
|
CHECK_UPDATE_RELEASE="$latest"
|
||||||
msg_info "New release available: v${latest} (current: v${current:-none})"
|
msg_info "New release available: v${latest} (current: v${current:-none})"
|
||||||
: >"$current_file"
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user