latest_release_branch.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bash
  2. set -eEuo pipefail
  3. # Get list of release- branches
  4. RELEASE_BRANCHES="$(git branch -r | grep -v mergify | grep '/release-' | cut -d'/' -f2 | sort | uniq)"
  5. LATEST_RELEASE_BRANCH=""
  6. MAX_TRIES=2
  7. TRY=1
  8. until [ -n "${LATEST_RELEASE_BRANCH}" ] || [ ${TRY} -gt ${MAX_TRIES} ]; do
  9. LATEST_RELEASE_BRANCH="$(echo "${RELEASE_BRANCHES}" | sort --version-sort | tail -n 1 | cut -d'/' -f2)"
  10. BRANCH_VERSION="v$(echo "${LATEST_RELEASE_BRANCH}" | cut -d'-' -f2-)"
  11. # Get tags for the release version and filter out any alpha or beta versions
  12. set +o pipefail
  13. set +e
  14. TAGS="$(git tag | grep -F "${BRANCH_VERSION}.0" | grep -Ev "alpha|beta")"
  15. set -o pipefail
  16. set -e
  17. # If the list is empty remove last line from $RELEASE_BRANCHES and
  18. # clear $LATEST_RELEASE_BRANCH var
  19. if [ -z "${TAGS}" ]; then
  20. LATEST_RELEASE_BRANCH=""
  21. RELEASE_BRANCHES="$(echo "${RELEASE_BRANCHES}" | sed '$d')"
  22. fi
  23. (( TRY++ ))
  24. done
  25. if [ -z "${LATEST_RELEASE_BRANCH}" ]; then
  26. echo "Failed to find latest released release branch!"
  27. exit 1
  28. fi
  29. echo "${LATEST_RELEASE_BRANCH}"