cut.sh 6.7 KB

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