Improve version extraction with stderr logging in get_latest_version
This commit is contained in:
parent
5f554a5b76
commit
a29fa93e1e
1 changed files with 24 additions and 14 deletions
|
|
@ -45,20 +45,30 @@ backup_forgejo() {
|
||||||
|
|
||||||
# Get the latest Forgejo version
|
# Get the latest Forgejo version
|
||||||
get_latest_version() {
|
get_latest_version() {
|
||||||
log "Checking for the latest Forgejo version..."
|
# Redirect log output to stderr so it doesn't get captured
|
||||||
|
log "Checking for the latest Forgejo version..." >&2
|
||||||
# Fetch the latest version from the Forgejo API with error handling
|
|
||||||
local latest_version
|
local response
|
||||||
latest_version=$(curl -s --max-time 10 https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/latest | \
|
local latest_version
|
||||||
jq -r '.tag_name' | \
|
|
||||||
sed 's/^v//')
|
response=$(curl -s --max-time 10 https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/latest)
|
||||||
|
|
||||||
if [ -z "$latest_version" ]; then
|
# Check if response contains expected field (also redirect to stderr)
|
||||||
log "ERROR: Failed to retrieve the latest version from Codeberg API."
|
if ! echo "$response" | jq -e '.tag_name' > /dev/null; then
|
||||||
exit 1
|
log "ERROR: Invalid response from Codeberg API." >&2
|
||||||
fi
|
log "Response was: $response" >&2
|
||||||
|
exit 1
|
||||||
echo "$latest_version"
|
fi
|
||||||
|
|
||||||
|
latest_version=$(echo "$response" | jq -r '.tag_name' | sed 's/^v//')
|
||||||
|
|
||||||
|
if [ -z "$latest_version" ]; then
|
||||||
|
log "ERROR: Failed to retrieve the latest version from Codeberg API." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Only output the version number
|
||||||
|
echo "$latest_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get current version
|
# Get current version
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue