cut.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. #!/usr/bin/env bash
  2. ## cut a new 5.x release for EMQX (opensource or enterprise).
  3. set -euo pipefail
  4. [ "${DEBUG:-}" = 1 ] && set -x
  5. # ensure dir
  6. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/../.."
  7. usage() {
  8. cat <<EOF
  9. $0 RELEASE_GIT_TAG [option]
  10. RELEASE_GIT_TAG is a 'v*' or 'e*' tag for example:
  11. v5.1.1
  12. e5.1.0-beta.6
  13. options:
  14. -h|--help: Print this usage.
  15. -b|--base: Specify the current release base branch, can be one of
  16. release-55
  17. release-56
  18. NOTE: this option should be used when --dryrun.
  19. --dryrun: Do not actually create the git tag.
  20. --skip-appup: Skip checking appup
  21. Useful when you are sure that appup is already updated'
  22. --prev-tag <tag>: Provide the prev tag to automatically generate changelogs
  23. If this option is absent, the tag found by git describe will be used
  24. For 5.X series the current working branch must be 'release-5X'
  25. --.--[ master ]---------------------------.-----------.---
  26. \\ /
  27. \`---[release-5X]----(v5.4.0 | e5.4.0)
  28. EOF
  29. }
  30. logerr() {
  31. echo "$(tput setaf 1)ERROR: $1$(tput sgr0)"
  32. }
  33. logwarn() {
  34. echo "$(tput setaf 3)WARNING: $1$(tput sgr0)"
  35. }
  36. logmsg() {
  37. echo "INFO: $1"
  38. }
  39. TAG="${1:-}"
  40. case "$TAG" in
  41. v*)
  42. TAG_PREFIX='v'
  43. PROFILE='emqx'
  44. SKIP_APPUP='yes'
  45. ;;
  46. e*)
  47. TAG_PREFIX='e'
  48. PROFILE='emqx-enterprise'
  49. #TODO change to no when we are ready to support hot-upgrade
  50. SKIP_APPUP='yes'
  51. ;;
  52. -h|--help)
  53. usage
  54. exit 0
  55. ;;
  56. *)
  57. logerr "Unknown version tag $TAG"
  58. usage
  59. exit 1
  60. ;;
  61. esac
  62. shift 1
  63. DRYRUN='no'
  64. while [ "$#" -gt 0 ]; do
  65. case $1 in
  66. -h|--help)
  67. usage
  68. exit 0
  69. ;;
  70. --skip-appup)
  71. shift
  72. SKIP_APPUP='yes'
  73. ;;
  74. --dryrun)
  75. shift
  76. DRYRUN='yes'
  77. ;;
  78. -b|--base)
  79. BASE_BR="${2:-}"
  80. if [ -z "${BASE_BR}" ]; then
  81. logerr "Must specify which base branch"
  82. exit 1
  83. fi
  84. shift 2
  85. ;;
  86. --prev-tag)
  87. shift
  88. PREV_TAG="$1"
  89. shift
  90. ;;
  91. *)
  92. logerr "Unknown option $1"
  93. exit 1
  94. ;;
  95. esac
  96. done
  97. rel_branch() {
  98. local tag="$1"
  99. case "$tag" in
  100. v5.5.*)
  101. echo 'release-55'
  102. ;;
  103. e5.5.*)
  104. echo 'release-55'
  105. ;;
  106. v5.6.*)
  107. echo 'release-56'
  108. ;;
  109. e5.6.*)
  110. echo 'release-56'
  111. ;;
  112. v5.7.*)
  113. echo 'release-57'
  114. ;;
  115. e5.7.*)
  116. echo 'release-57'
  117. ;;
  118. *)
  119. logerr "Unsupported version tag $TAG"
  120. exit 1
  121. ;;
  122. esac
  123. }
  124. ## Ensure the current work branch
  125. assert_work_branch() {
  126. local tag="$1"
  127. local release_branch
  128. release_branch="$(rel_branch "$tag")"
  129. local base_branch
  130. base_branch="${BASE_BR:-$(git branch --show-current)}"
  131. if [ "$base_branch" != "$release_branch" ]; then
  132. logerr "Base branch: $base_branch"
  133. logerr "Relase tag must be on the release branch: $release_branch"
  134. logerr "or must use -b|--base option to specify which release branch is current branch based on"
  135. exit 1
  136. fi
  137. }
  138. assert_work_branch "$TAG"
  139. ## Ensure no dirty changes
  140. assert_not_dirty() {
  141. local diff
  142. diff="$(git diff --name-only)"
  143. if [ -n "$diff" ]; then
  144. logerr "Git status is not clean? Changed files:"
  145. logerr "$diff"
  146. exit 1
  147. fi
  148. }
  149. assert_not_dirty
  150. ## Assert that the tag is not already created
  151. assert_tag_absent() {
  152. local tag="$1"
  153. ## Fail if the tag already exists
  154. EXISTING="$(git tag --list "$tag")"
  155. if [ -n "$EXISTING" ]; then
  156. logerr "$tag already released?"
  157. logerr 'This script refuse to force re-tag.'
  158. logerr 'If re-tag is intended, you must first delete the tag from both local and remote'
  159. exit 1
  160. fi
  161. }
  162. assert_tag_absent "$TAG"
  163. RELEASE_VSN=$(./pkg-vsn.sh "$PROFILE" --release)
  164. ## Assert package version is updated to the tag which is being created
  165. assert_release_version() {
  166. local tag="$1"
  167. if [ "${TAG_PREFIX}${RELEASE_VSN}" != "${tag}" ]; then
  168. logerr "The release version ($RELEASE_VSN) is different from the desired git tag."
  169. logerr "Update the release version in emqx_release.hrl"
  170. exit 1
  171. fi
  172. }
  173. assert_release_version "$TAG"
  174. ## Check if all upstream branches are merged
  175. SYNC_REMOTES_ARGS=
  176. [ -n "${BASE_BR:-}" ] && SYNC_REMOTES_ARGS="--base $BASE_BR $SYNC_REMOTES_ARGS"
  177. [ "$DRYRUN" = 'yes' ] && SYNC_REMOTES_ARGS="--dryrun $SYNC_REMOTES_ARGS"
  178. # shellcheck disable=SC2086
  179. ./scripts/rel/sync-remotes.sh $SYNC_REMOTES_ARGS
  180. ## Check if the Chart versions are in sync
  181. ./scripts/rel/check-chart-vsn.sh "$PROFILE"
  182. ## Check if app versions are bumped
  183. ./scripts/apps-version-check.sh
  184. ## Ensure appup files are updated
  185. if [ "$SKIP_APPUP" = 'no' ]; then
  186. logmsg "Checking appups"
  187. ./scripts/update-appup.sh "$PROFILE" --check
  188. else
  189. logmsg "Skipped checking appup updates"
  190. fi
  191. ## Ensure relup paths are updated
  192. ## TODO: add relup path db
  193. #./scripts/relup-base-vsns.escript check-vsn-db "$RELEASE_VSN" "$RELUP_PATHS"
  194. ## Run some additional checks (e.g. some for enterprise edition only)
  195. CHECKS_DIR="./scripts/rel/checks"
  196. if [ -d "${CHECKS_DIR}" ]; then
  197. CHECKS="$(find "${CHECKS_DIR}" -name "*.sh" -print0 2>/dev/null | xargs -0)"
  198. for c in $CHECKS; do
  199. logmsg "Executing $c"
  200. $c
  201. done
  202. fi
  203. check_changelog() {
  204. local file="changes/${TAG}.en.md"
  205. if [ ! -f "$file" ]; then
  206. logerr "Changelog file $file is missing."
  207. logerr "Generate it with command: ./scripts/rel/format-changelog.sh -b ${PREV_TAG} -v ${TAG} > ${file}"
  208. exit 1
  209. fi
  210. }
  211. check_bpapi() {
  212. local fname
  213. case "$TAG" in
  214. *.0)
  215. fname="$(echo "$TAG" | sed 's/^e//; s/\.0$//')"
  216. fpath="apps/emqx/test/emqx_static_checks_data/${fname}.bpapi2"
  217. logmsg "Checking $fpath"
  218. if [ ! -f "$fpath" ]; then
  219. logerr "BPAPI file missing: $fpath"
  220. exit 1
  221. fi
  222. ;;
  223. *)
  224. true
  225. ;;
  226. esac
  227. }
  228. case "$TAG" in
  229. *rc*)
  230. true
  231. ;;
  232. *alpha*)
  233. true
  234. ;;
  235. *beta*)
  236. true
  237. ;;
  238. e*)
  239. check_bpapi
  240. check_changelog
  241. ;;
  242. v*)
  243. check_changelog
  244. ;;
  245. esac
  246. if [ "$DRYRUN" = 'yes' ]; then
  247. logmsg "Release tag is ready to be created with command: git tag $TAG"
  248. else
  249. git tag "$TAG"
  250. logmsg "$TAG is created OK."
  251. logwarn "Don't forget to push the tag!"
  252. echo "git push origin $TAG"
  253. fi