Skip to content

Commit

Permalink
fix: modify install script to prioritize stable releases
Browse files Browse the repository at this point in the history
Before, the script was picking whatever was the most recent released tag.
This is not necessarily correct, as you can have tags for betas, and release candidates.
We don't want customers installing the "latest" and end up using an unstable build.

Now, we sort all the tags by the semantic version number, and then
we pick the first stable one (not containing a dash).
If we can't find any stable one, we pick the top one in the list.
  • Loading branch information
micovery committed May 1, 2024
1 parent 58fda1a commit 1ab269f
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,44 @@ checkCurrentVersion() {
fi
}


sortSemver() {
local lines=""
while read version; do
if [[ -z "${lines}" ]] ; then
lines=$(printf '%s' "${version}")
else
lines=$(printf '%s\n%s' "${lines}" "${version}")
fi
done
echo "$lines" | sed -r 's:^v::' | sed -r 's:-:~:' | sort -r -V | sed -r 's:^:v:' | sed -r 's:~:-:'
}

pickLatestRelease() {
local first=""
while read version; do
first="${version}"
if [[ "${version}" != *"-"* ]] ; then
echo "${version}"
return
fi
done
echo "${first}"
}

getReleasedTags() {
local releaseUrl="${1}"
curl -s "${releaseUrl}" | grep "tag_name" | sed -r 's;^[^:]+:[^"]*"([^"]+)".*;\1;'
}

getLatestRelease() {
local releaseUrl="https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/releases"
local latest_release=""

latest_release=$(curl -s $releaseUrl | grep \"tag_name\" | grep -v rc | awk 'NR==1{print $2}' | sed -n 's/\"\(.*\)\",/\1/p')
latest_release=$(getReleasedTags $releaseUrl | sortSemver | pickLatestRelease)
ret_val=$latest_release
}


createTmpDir() {
ret_val=$(mktemp -dt ${BINARY_FILENAME}-tmp)
}
Expand Down

0 comments on commit 1ab269f

Please # to comment.