cut.sh 7.0 KB

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