cut.sh 6.5 KB

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