relup-base-vsns.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. ## This script prints the relup upgrade base versions
  4. ## for the given EMQX edition (specified as first arg)
  5. ##
  6. ## The second argument is the current release version
  7. ## if not provided, it's taken from pkg-vsn.sh
  8. usage() {
  9. echo "Usage: $0 <EMQX_PROFILE> [<CURRENT_VERSION>]"
  10. echo "e.g. $0 enterprise 4.3.10"
  11. exit 1
  12. }
  13. parse_semver() {
  14. echo "$1" | tr '.|-' ' '
  15. }
  16. PROFILE="${1:-}"
  17. [ -z "${PROFILE}" ] && usage
  18. ## Get the current release version
  19. ## e.g.
  20. ## 5.0.0 when GA
  21. ## 5.0.0-beta.3 when pre-release
  22. ## 5.0.0-beta.3.abcdef00 when developing
  23. CUR="${2:-}"
  24. if [ -z "${CUR}" ]; then
  25. CUR="$(./pkg-vsn.sh "$PROFILE")"
  26. fi
  27. # shellcheck disable=SC2207
  28. CUR_SEMVER=($(parse_semver "$CUR"))
  29. if [ "${#CUR_SEMVER[@]}" -lt 3 ]; then
  30. echo "$CUR is not Major.Minor.Patch"
  31. usage
  32. fi
  33. ## when the current version has no suffix such as -abcdef00
  34. ## it is a formal release
  35. if [ "${#CUR_SEMVER[@]}" -eq 3 ]; then
  36. IS_RELEASE=true
  37. else
  38. IS_RELEASE=false
  39. fi
  40. case "${PROFILE}" in
  41. *enterprise*)
  42. GIT_TAG_PREFIX="e"
  43. ;;
  44. *)
  45. GIT_TAG_PREFIX="v"
  46. ;;
  47. esac
  48. while read -r git_tag; do
  49. # shellcheck disable=SC2207
  50. semver=($(parse_semver "$git_tag"))
  51. if [ "${#semver[@]}" -eq 3 ] && [ "${semver[2]}" -le "${CUR_SEMVER[2]}" ]; then
  52. if [ ${IS_RELEASE} = true ] && [ "${semver[2]}" -eq "${CUR_SEMVER[2]}" ] ; then
  53. # do nothing
  54. # exact match, do not print current version
  55. # because current version is not an upgrade base
  56. true
  57. else
  58. echo "$git_tag"
  59. fi
  60. fi
  61. done < <(git tag -l "${GIT_TAG_PREFIX}${CUR_SEMVER[0]}.${CUR_SEMVER[1]}.*")