cut.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #!/usr/bin/env bash
  2. ## cut a new 5.x release for EMQX (opensource or enterprise).
  3. set -euo pipefail
  4. if [ "${DEBUG:-}" = 1 ]; then
  5. set -x
  6. fi
  7. # ensure dir
  8. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/../.."
  9. usage() {
  10. cat <<EOF
  11. $0 RELEASE_GIT_TAG [option]
  12. RELEASE_GIT_TAG is a 'v*' or 'e*' tag for example:
  13. v5.0.12
  14. e5.0.0-beta.6
  15. options:
  16. -h|--help: Print this usage.
  17. -b|--base: Specify the current release base branch, can be one of
  18. release-50
  19. NOTE: this option should be used when --dryrun.
  20. --dryrun: Do not actually create the git tag.
  21. --skip-appup: Skip checking appup
  22. Useful when you are sure that appup is already updated'
  23. NOTE: For 5.0 series the current working branch must be 'release-50' for opensource edition
  24. and 'release-e50' for enterprise edition.
  25. --.--[ master ]---------------------------.-----------.---
  26. \\ /
  27. \`---[release-50]----(v5.0.12 | e5.0.0)
  28. EOF
  29. }
  30. logerr() {
  31. echo "$(tput setaf 1)ERROR: $1$(tput sgr0)"
  32. }
  33. logmsg() {
  34. echo "INFO: $1"
  35. }
  36. TAG="${1:-}"
  37. case "$TAG" in
  38. v*)
  39. TAG_PREFIX='v'
  40. PROFILE='emqx'
  41. SKIP_APPUP='yes'
  42. ;;
  43. e*)
  44. TAG_PREFIX='e'
  45. PROFILE='emqx-enterprise'
  46. SKIP_APPUP='no'
  47. ;;
  48. -h|--help)
  49. usage
  50. exit 0
  51. ;;
  52. *)
  53. logerr "Unknown version tag $TAG"
  54. usage
  55. exit 1
  56. ;;
  57. esac
  58. shift 1
  59. DRYRUN='no'
  60. while [ "$#" -gt 0 ]; do
  61. case $1 in
  62. -h|--help)
  63. usage
  64. exit 0
  65. ;;
  66. --skip-appup)
  67. shift
  68. SKIP_APPUP='yes'
  69. ;;
  70. --dryrun)
  71. shift
  72. DRYRUN='yes'
  73. ;;
  74. -b|--base)
  75. BASE_BR="${2:-}"
  76. if [ -z "${BASE_BR}" ]; then
  77. logerr "Must specify which base branch"
  78. exit 1
  79. fi
  80. shift 2
  81. ;;
  82. *)
  83. logerr "Unknown option $1"
  84. exit 1
  85. ;;
  86. esac
  87. done
  88. rel_branch() {
  89. local tag="$1"
  90. case "$tag" in
  91. v5.0.*)
  92. echo 'release-50'
  93. ;;
  94. e5.0.*)
  95. echo 'release-50'
  96. ;;
  97. *)
  98. logerr "Unsupported version tag $TAG"
  99. exit 1
  100. ;;
  101. esac
  102. }
  103. ## Ensure the current work branch
  104. assert_work_branch() {
  105. local tag="$1"
  106. local release_branch
  107. release_branch="$(rel_branch "$tag")"
  108. local base_branch
  109. base_branch="${BASE_BR:-$(git branch --show-current)}"
  110. if [ "$base_branch" != "$release_branch" ]; then
  111. logerr "Base branch: $base_branch"
  112. logerr "Relase tag must be on the release branch: $release_branch"
  113. logerr "or must use -b|--base option to specify which release branch is current branch based on"
  114. exit 1
  115. fi
  116. }
  117. assert_work_branch "$TAG"
  118. ## Ensure no dirty changes
  119. assert_not_dirty() {
  120. local diff
  121. diff="$(git diff --name-only)"
  122. if [ -n "$diff" ]; then
  123. logerr "Git status is not clean? Changed files:"
  124. logerr "$diff"
  125. exit 1
  126. fi
  127. }
  128. assert_not_dirty
  129. ## Assert that the tag is not already created
  130. assert_tag_absent() {
  131. local tag="$1"
  132. ## Fail if the tag already exists
  133. EXISTING="$(git tag --list "$tag")"
  134. if [ -n "$EXISTING" ]; then
  135. logerr "$tag already released?"
  136. logerr 'This script refuse to force re-tag.'
  137. logerr 'If re-tag is intended, you must first delete the tag from both local and remote'
  138. exit 1
  139. fi
  140. }
  141. assert_tag_absent "$TAG"
  142. PKG_VSN=$(./pkg-vsn.sh "$PROFILE")
  143. ## Assert package version is updated to the tag which is being created
  144. assert_release_version() {
  145. local tag="$1"
  146. # shellcheck disable=SC2001
  147. pkg_vsn="$(echo "$PKG_VSN" | sed 's/-g[0-9a-f]\{8\}$//g')"
  148. if [ "${TAG_PREFIX}${pkg_vsn}" != "${tag}" ]; then
  149. logerr "The release version ($pkg_vsn) is different from the desired git tag."
  150. logerr "Update the release version in emqx_release.hrl"
  151. exit 1
  152. fi
  153. }
  154. assert_release_version "$TAG"
  155. ## Check if all upstream branches are merged
  156. if [ -z "${BASE_BR:-}" ]; then
  157. ./scripts/rel/sync-remotes.sh
  158. else
  159. ./scripts/rel/sync-remotes.sh --base "$BASE_BR"
  160. fi
  161. ## Check if the Chart versions are in sync
  162. ./scripts/rel/check-chart-vsn.sh "$PROFILE"
  163. ## Check if app versions are bumped
  164. ./scripts/apps-version-check.sh
  165. ## Ensure appup files are updated
  166. if [ "$SKIP_APPUP" = 'no' ]; then
  167. logmsg "Checking appups"
  168. ./scripts/update-appup.sh "$PROFILE" --check
  169. else
  170. logmsg "Skipped checking appup updates"
  171. fi
  172. ## Ensure relup paths are updated
  173. ## TODO: add relup path db
  174. #./scripts/relup-base-vsns.escript check-vsn-db "$PKG_VSN" "$RELUP_PATHS"
  175. ## Run some additional checks (e.g. some for enterprise edition only)
  176. CHECKS_DIR="./scripts/rel/checks"
  177. if [ -d "${CHECKS_DIR}" ]; then
  178. CHECKS="$(find "${CHECKS_DIR}" -name "*.sh" -print0 2>/dev/null | xargs -0)"
  179. for c in $CHECKS; do
  180. logmsg "Executing $c"
  181. $c
  182. done
  183. fi
  184. if [ "$DRYRUN" = 'yes' ]; then
  185. logmsg "Release tag is ready to be created with command: git tag $TAG"
  186. else
  187. git tag "$TAG"
  188. logmsg "$TAG is created OK."
  189. fi