relup-base-vsns.sh 1.7 KB

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