cut.sh 7.3 KB

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