cut.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. v5.8.*)
  119. echo 'release-58'
  120. ;;
  121. e5.8.*)
  122. echo 'release-58'
  123. ;;
  124. *)
  125. logerr "Unsupported version tag $TAG"
  126. exit 1
  127. ;;
  128. esac
  129. }
  130. assert_profile() {
  131. local tag="$1"
  132. local allowed_prefix
  133. if [ -f .emqx-platform ]; then
  134. allowed_prefix='e'
  135. else
  136. allowed_prefix='v'
  137. fi
  138. if [[ "${tag}" != "${allowed_prefix}"* ]]; then
  139. logerr "Expecting a '${allowed_prefix}' tag on this commit"
  140. exit 1
  141. fi
  142. }
  143. assert_profile "$TAG"
  144. ## Ensure the current work branch
  145. assert_work_branch() {
  146. local tag="$1"
  147. local release_branch
  148. release_branch="$(rel_branch "$tag")"
  149. local base_branch
  150. base_branch="${BASE_BR:-$(git branch --show-current)}"
  151. if [ "$base_branch" != "$release_branch" ]; then
  152. logerr "Base branch: $base_branch"
  153. logerr "Relase tag must be on the release branch: $release_branch"
  154. logerr "or must use -b|--base option to specify which release branch is current branch based on"
  155. exit 1
  156. fi
  157. }
  158. assert_work_branch "$TAG"
  159. ## Ensure no dirty changes
  160. assert_not_dirty() {
  161. local diff
  162. diff="$(git diff --name-only)"
  163. if [ -n "$diff" ]; then
  164. logerr "Git status is not clean? Changed files:"
  165. logerr "$diff"
  166. exit 1
  167. fi
  168. }
  169. assert_not_dirty
  170. ## Assert that the tag is not already created
  171. assert_tag_absent() {
  172. local tag="$1"
  173. ## Fail if the tag already exists
  174. EXISTING="$(git tag --list "$tag")"
  175. if [ -n "$EXISTING" ]; then
  176. logerr "$tag already released?"
  177. logerr 'This script refuse to force re-tag.'
  178. logerr 'If re-tag is intended, you must first delete the tag from both local and remote'
  179. exit 1
  180. fi
  181. }
  182. assert_tag_absent "$TAG"
  183. RELEASE_VSN=$(./pkg-vsn.sh "$PROFILE" --release)
  184. ## Assert package version is updated to the tag which is being created
  185. assert_release_version() {
  186. local tag="$1"
  187. if [ "${TAG_PREFIX}${RELEASE_VSN}" != "${tag}" ]; then
  188. logerr "The release version ($RELEASE_VSN) is different from the desired git tag."
  189. logerr "Update the release version in emqx_release.hrl"
  190. exit 1
  191. fi
  192. }
  193. assert_release_version "$TAG"
  194. ## Check if all upstream branches are merged
  195. SYNC_REMOTES_ARGS=
  196. [ -n "${BASE_BR:-}" ] && SYNC_REMOTES_ARGS="--base $BASE_BR $SYNC_REMOTES_ARGS"
  197. [ "$DRYRUN" = 'yes' ] && SYNC_REMOTES_ARGS="--dryrun $SYNC_REMOTES_ARGS"
  198. # shellcheck disable=SC2086
  199. ./scripts/rel/sync-remotes.sh $SYNC_REMOTES_ARGS
  200. ## Check if the Chart versions are in sync
  201. ./scripts/rel/check-chart-vsn.sh "$PROFILE"
  202. ## Check if app versions are bumped
  203. ./scripts/apps-version-check.sh
  204. ## Ensure appup files are updated
  205. if [ "$SKIP_APPUP" = 'no' ]; then
  206. logmsg "Checking appups"
  207. ./scripts/update-appup.sh "$PROFILE" --check
  208. else
  209. logmsg "Skipped checking appup updates"
  210. fi
  211. ## Ensure relup paths are updated
  212. ## TODO: add relup path db
  213. #./scripts/relup-base-vsns.escript check-vsn-db "$RELEASE_VSN" "$RELUP_PATHS"
  214. ## Run some additional checks (e.g. some for enterprise edition only)
  215. CHECKS_DIR="./scripts/rel/checks"
  216. if [ -d "${CHECKS_DIR}" ]; then
  217. CHECKS="$(find "${CHECKS_DIR}" -name "*.sh" -print0 2>/dev/null | xargs -0)"
  218. for c in $CHECKS; do
  219. logmsg "Executing $c"
  220. $c
  221. done
  222. fi
  223. check_changelog() {
  224. local file="changes/${TAG}.en.md"
  225. if [ ! -f "$file" ]; then
  226. logerr "Changelog file $file is missing."
  227. logerr "Generate it with command: ./scripts/rel/format-changelog.sh -b ${PREV_TAG} -v ${TAG} > ${file}"
  228. exit 1
  229. fi
  230. }
  231. check_bpapi() {
  232. local fname
  233. case "$TAG" in
  234. *.0)
  235. fname="$(echo "$TAG" | sed 's/^e//; s/\.0$//')"
  236. fpath="apps/emqx/test/emqx_static_checks_data/${fname}.bpapi2"
  237. logmsg "Checking $fpath"
  238. if [ ! -f "$fpath" ]; then
  239. logerr "BPAPI file missing: $fpath"
  240. exit 1
  241. fi
  242. ;;
  243. *)
  244. true
  245. ;;
  246. esac
  247. }
  248. case "$TAG" in
  249. *rc*)
  250. true
  251. ;;
  252. *alpha*)
  253. true
  254. ;;
  255. *beta*)
  256. true
  257. ;;
  258. e*)
  259. check_bpapi
  260. check_changelog
  261. ;;
  262. v*)
  263. check_changelog
  264. ;;
  265. esac
  266. if [ "$DRYRUN" = 'yes' ]; then
  267. logmsg "Release tag is ready to be created with command: git tag $TAG"
  268. else
  269. git tag "$TAG"
  270. logmsg "$TAG is created OK."
  271. PUSH_TO="both emqx.git and emqx-platform.git!"
  272. if [ -f .emqx-platform ]; then
  273. PUSH_TO="emqx-platform.git but NOT emqx.git!"
  274. fi
  275. logwarn "Don't forget to push the tag to ${PUSH_TO}"
  276. echo "git push origin $TAG"
  277. fi