From 3aeb4cd05b5dede8e0c299f3ca90b380bd529955 Mon Sep 17 00:00:00 2001 From: Valeriy Svydenko Date: Thu, 14 Sep 2023 16:43:33 +0300 Subject: [PATCH] chore: add retry loop to get versiosns Signed-off-by: Valeriy Svydenko --- .../build/scripts/download_vsix.sh | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/dependencies/che-plugin-registry/build/scripts/download_vsix.sh b/dependencies/che-plugin-registry/build/scripts/download_vsix.sh index 6fb93e7153..2d35e32c39 100755 --- a/dependencies/che-plugin-registry/build/scripts/download_vsix.sh +++ b/dependencies/che-plugin-registry/build/scripts/download_vsix.sh @@ -46,32 +46,46 @@ function initTest() { echo -n -e "${BOLD}\n${EMOJI_HEADER} ${1}${RESETSTYLE} ... " } -function getOpenVSXData(){ +vsixMetadata="" #now global so it can be set/checked via function +getMetadata(){ vsixName=$1 key=$2 - parameters=$3 - - # build the request url - if [[ -n "$parameters" ]]; then - url="https://open-vsx.org/api/${vsixName}/${key}?${parameters}" - else - url="https://open-vsx.org/api/${vsixName}/${key}" - fi # check there is no error field in the metadata and retry if there is for j in 1 2 3 4 5 do - result=$(curl -sLS "${url}") - if [[ $(echo "${result}" | jq -r ".error") != null ]]; then - echo "Attempt $j/5: Error while getting metadata for ${vsixFullName} version ${key}" + vsixMetadata=$(curl -sLS "https://open-vsx.org/api/${vsixName}/${key}") + if [[ $(echo "${vsixMetadata}" | jq -r ".error") != null ]]; then + echo "Attempt $j/5: Error while getting metadata for ${vsixName} version ${key}" + + if [[ $j -eq 5 ]]; then + echo "[ERROR] Maximum of 5 attempts reached - must exit!" + exit 1 + fi + continue + else + break + fi + done +} + +versionsPage="" +getVersions(){ + vsixName=$1 + # check the versions page is empty and retry if it is + for j in 1 2 3 4 5 + do + versionsPage=$(curl -sLS "https://open-vsx.org/api/${vsixName}/versions?size=200") + totalSize=$(echo "${versionsPage}" | jq -r ".totalSize") + if [[ "$totalSize" != "null" && "$totalSize" -eq 0 ]]; then + echo "Attempt $j/5: Error while getting versions for ${vsixName}" if [[ $j -eq 5 ]]; then - echo "[ERROR] Maximum of 5 attempts reached - must exit with failure!" + echo "[ERROR] Maximum of 5 attempts reached - must exit!" exit 1 fi continue else - echo "$result" break fi done @@ -110,7 +124,7 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do # grab metadata for the vsix file # if version wasn't set, use latest if [[ $vsixVersion == null ]]; then - versionsPage=$(getOpenVSXData "${vsixName}" "versions" "size=200") + getVersions "${vsixName}" # if version wasn't set in json, grab it from metadata and add it into the file # get all versions of the extension @@ -125,7 +139,7 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do resultedVersion=null while IFS=$'\t' read -r key value; do # get metadata for the version - vsixMetadata=$(getOpenVSXData "${vsixName}" "${key}") + getMetadata "${vsixName}" "${key}" # check if the version is pre-release preRelease=$(echo "${vsixMetadata}" | jq -r '.preRelease') @@ -164,7 +178,7 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do jq --argjson i "$i" --arg version "$vsixVersion" '.[$i] += { "version": $version }' "$openvsxJson" > tmp.json mv tmp.json "$openvsxJson" else - vsixMetadata=$(getOpenVSXData "${vsixName}" "${vsixVersion}") + getMetadata "${vsixName}" "${vsixVersion}" fi # extract the download link from the json metadata