cut.sh 7.1 KB

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