Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions scripts/updates/api/termux_github_api_get_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ termux_github_api_get_tag() {
# echo interpolates control characters, which jq does not like.
response="$(printf "%s\n" "${response%|*}")"

local tag_name=""
local tag_name="" err=0
case "${http_code}" in
200)
tag_name="$(jq --exit-status --raw-output "${jq_filter}" <<< "${response}")"
tag_name="$(jq --exit-status --raw-output "${jq_filter}" <<< "${response}")" || err=1
;;
404)
termux_error_exit <<-EndOfError
Expand Down Expand Up @@ -134,8 +134,25 @@ termux_github_api_get_tag() {
fi
)'.
EndOfError
else
err=1
fi
;;
esac

# If the input failed to parse log it for the issue.
if (( err )); then
termux_error_exit <<-EndOfError
${CI:+::group::}ERROR: Response seems to be invalid JSON.
Codepath: ${FUNCNAME[0]}
API url : ${api_url}
API path: ${api_path}
\`\`\`json
${response}
\`\`\`
${CI:+::endgroup::}
EndOfError
fi

echo "${tag_name}"
}
21 changes: 19 additions & 2 deletions scripts/updates/api/termux_gitlab_api_get_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ termux_gitlab_api_get_tag() {
# echo interpolates control characters, which jq does not like.
response="$(printf "%s\n" "${response%|*}")"

local tag_name=""
local tag_name="" err=0
case "${http_code}" in
200)
tag_name="$(jq --exit-status --raw-output "${jq_filter}" <<< "${response}")"
tag_name="$(jq --exit-status --raw-output "${jq_filter}" <<< "${response}")" || err=1
;;
404)
termux_error_exit <<-EndOfError
Expand Down Expand Up @@ -100,8 +100,25 @@ termux_gitlab_api_get_tag() {
fi
)'.
EndOfError
else
err=1
fi
;;
esac

# If the input failed to parse log it for the issue.
if (( err )); then
termux_error_exit <<-EndOfError
${CI:+::group::}ERROR: Response seems to be invalid JSON.
Codepath: ${FUNCNAME[0]}
API url : ${api_url}
API path: ${api_path}
\`\`\`json
${response}
\`\`\`
${CI:+::endgroup::}
EndOfError
fi

echo "${tag_name}"
}
22 changes: 20 additions & 2 deletions scripts/updates/api/termux_repology_api_get_latest_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,28 @@
# But hopefully, all this can be avoided if TERMUX_PKG_UPDATE_VERSION_REGEXP is set.
#
termux_repology_api_get_latest_version() {
# shellcheck source=scripts/build/termux_error_exit.sh
declare -f termux_error_exit >/dev/null ||
. "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../../build/termux_error_exit.sh" # realpath is used to resolve symlinks.

if [[ -z "$1" ]]; then
termux_error_exit "Usage: ${FUNCNAME[0]} PKG_NAME"
fi

# Why `--arg`? See: https://stackoverflow.com/a/54674832/15086226; `sub` strips the leading 'v'
jq -r --arg pkg "$1" '.[$pkg] // "null" | sub("^v";"")' "$TERMUX_REPOLOGY_DATA_FILE"
Comment on lines -18 to -19
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I removed the | sub("^v";"") part of the jq expression it felt appropriate to update the comment as well.
The prefix stripping is done by termux_pkg_upgrade_version.

# Remove any leading non-digits as that would not be a valid version.
# shellcheck disable=SC2001 # This is something parameter expansion can't handle well, so we use sed.
LATEST_VERSION="$(sed -e "s/^[^0-9]*//" <<< "$LATEST_VERSION")"

We already made the analogous change to termux_git{hub,lab}_api_get_tag in #27576 (61a53e3).

local tag_name
# We are performing a key match for `$pkg` (function `$1`) in the repology data file and return its value.
if ! tag_name="$(jq --exit-status --raw-output --arg pkg "$1" '.[$pkg] // "null"' "$TERMUX_REPOLOGY_DATA_FILE")"; then
# If the input failed to parse log it for the issue.
termux_error_exit <<-EndOfError
${CI:+::group::}ERROR: Response seems to be invalid JSON.
Codepath: ${FUNCNAME[0]}
\`\`\`json
$(<"$TERMUX_REPOLOGY_DATA_FILE")
\`\`\`
${CI:+::endgroup::}
EndOfError

fi

echo "${tag_name}"
}