diff --git a/update_demos.sh b/update_demos.sh index 13f18dd6..07a192b3 100755 --- a/update_demos.sh +++ b/update_demos.sh @@ -50,36 +50,39 @@ error_usage() } get_latest_tag() { - local mlrun_version="$1" - local git_owner="$2" - local git_repo="$3" - local git_base_url="$4" - local git_url="$5" - - local tag_prefix=`echo ${mlrun_version} | cut -d . -f1-2` - - # Fetch remote tags - local tags=$(git ls-remote --tags --refs --sort='v:refname' "${git_url}" "refs/tags/v${tag_prefix}.*") - - # Extract tag names - local tag_names=$(echo "$tags" | awk -F'/' '{print $NF}') - - # Find the latest release and RC - local latest_release="" - local latest_rc="" - for tag in $tag_names; do - if [[ $tag == *"rc"* ]]; then - latest_rc=$tag - else - latest_release=$tag - fi - done - - if [[ -z $latest_release ]]; then - echo $latest_rc - else - echo $latest_release - fi + local mlrun_version="$1" + local git_owner="$2" + local git_repo="$3" + local git_base_url="$4" # Unused in this function but can be useful for future enhancements + local git_url="$5" + + # Fetch tags from git + local tags=$(git ls-remote --tags --refs --sort='v:refname' "${git_url}" | awk '{print $2}') + + local latest_release="" + local latest_rc="" + + # Parse + while IFS= read -r tag; do + tag=${tag#refs/tags/} + + # Check if tag matches the target + if [[ $tag =~ ^v${mlrun_version} ]]; then + if [[ $tag == *"-rc"* ]]; then + latest_rc=$tag + else + latest_release=$tag + fi + fi + done <<< "$tags" + + if [[ -n "$latest_release" ]]; then + echo "$latest_release" + elif [[ -n "$latest_rc" ]]; then + echo "$latest_rc" + else + echo "No matching tags found." + fi } while :