cut.sh 6.8 KB

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