Skip to content

Commit

Permalink
Add retry loop for getting vsixMetadata since the internet is unrelia…
Browse files Browse the repository at this point in the history
…ble. Make start-services.sh and import-vsix.sh executable so they can be run locally without manual work.
  • Loading branch information
SDawley committed Jul 17, 2023
1 parent feaea06 commit 8afc672
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions build/dockerfiles/import-vsix.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ export OVSX_PAT=eclipse_che_token

containsElement () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }

vsixMetadata="" #now global so it can be set/checked via function
getMetadata(){
vsixName=$1
key=$2

# check there is no error field in the metadata and retry if there is
max_attempts=5
for i in 1 2 3 4 5
do
vsixMetadata=$(curl -sLS "https://open-vsx.org/api/${vsixName}/${key}")
if [[ $(echo "${vsixMetadata}" | jq -r ".error") != null ]]; then
echo "Attempt $i/5: Error while getting metadata for ${vsixFullName} version ${key}"
continue
else
break
fi
done
}

# pull vsix from OpenVSX
mkdir -p /tmp/vsix
Expand Down Expand Up @@ -68,8 +86,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
vsixMetadata=$(curl -sLS "https://open-vsx.org/api/${vsixName}/latest")

getMetadata $vsixName "latest"
# if version wasn't set in json, grab it from metadata and add it into the file
# get all versions of the extension
allVersions=$(echo "${vsixMetadata}" | jq -r '.allVersions')
Expand All @@ -79,12 +96,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=$(curl -sLS "https://open-vsx.org/api/${vsixName}/${key}")
# check there is no error field in the metadata
if [[ $(echo "${vsixMetadata}" | jq -r ".error") != null ]]; then
echo "Error while getting metadata for ${vsixFullName} version ${key}"
continue
fi
getMetadata $vsixName $key

# check if the version is pre-release
preRelease=$(echo "${vsixMetadata}" | jq -r '.preRelease')
Expand Down Expand Up @@ -120,14 +132,8 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do
vsixVersion=$resultedVersion
fi
else
vsixMetadata=$(curl -sLS "https://open-vsx.org/api/${vsixName}/${vsixVersion}")
getMetadata $vsixName $vsixVersion
fi
# check there is no error field in the metadata
if [[ $(echo "${vsixMetadata}" | jq -r ".error") != null ]]; then
echo "Error while getting metadata for ${vsixFullName}"
echo "${vsixMetadata}"
exit 1
fi

# extract the download link from the json metadata
vsixDownloadLink=$(echo "${vsixMetadata}" | jq -r '.files.download')
Expand Down
Empty file modified build/dockerfiles/start-services.sh
100644 → 100755
Empty file.

0 comments on commit 8afc672

Please sign in to comment.