From 5af30c6af826cfca019ba231ad7e711f91d1bc4e Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Thu, 3 Apr 2025 11:16:34 +0200 Subject: [PATCH] Update build.func --- misc/build.func | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/misc/build.func b/misc/build.func index 8705ad1..63d4db7 100644 --- a/misc/build.func +++ b/misc/build.func @@ -2258,6 +2258,57 @@ check_container_storage() { fi } +get_gh_release() { + local repo="$1" + local app="${repo##*/}" + local api_url="https://api.github.com/repos/$repo/releases/latest" + local header=() + local attempt=0 + local max_attempts=3 + local api_response tag + + echo "🔍 Checking latest release for: $repo" + + [[ -n "${GITHUB_TOKEN:-}" ]] && header=(-H "Authorization: token $GITHUB_TOKEN") + + until [[ $attempt -ge $max_attempts ]]; do + ((attempt++)) + $STD msg_info "[$attempt/$max_attempts] Fetching GitHub release for $repo...\n" + + if ! api_response=$(curl -fsSL "${header[@]}" "$api_url"); then + $STD msg_info "Request failed, retrying...\n" + sleep 2 + continue + fi + + if echo "$api_response" | grep -q "API rate limit exceeded"; then + msg_error "GitHub API rate limit exceeded." + return 1 + fi + + if echo "$api_response" | jq -e '.message == "Not Found"' &>/dev/null; then + msg_error "Repository not found: $repo" + return 1 + fi + + tag=$(echo "$api_response" | jq -r '.tag_name // .name // empty') + [[ "$tag" =~ ^v[0-9] ]] && tag="${tag:1}" + + if [[ -z "$tag" ]]; then + $STD msg_info "Empty tag received, retrying...\n" + sleep 2 + continue + fi + + $STD msg_ok "Found release: $tag for $repo" + echo "$tag" + return 0 + done + + msg_error "Failed to fetch release for $repo after $max_attempts attempts." + return 1 +} + start() { #source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/github.func) LOGDIR="/usr/local/community-scripts/logs"