cut.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #!/usr/bin/env bash
  2. ## cut a new 5.x release for EMQX (opensource or enterprise).
  3. set -euo pipefail
  4. if [ "${DEBUG:-}" = 1 ]; then
  5. set -x
  6. fi
  7. # ensure dir
  8. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/../.."
  9. usage() {
  10. cat <<EOF
  11. $0 RELEASE_GIT_TAG [option]
  12. RELEASE_GIT_TAG is a 'v*' or 'e*' tag for example:
  13. v5.0.12
  14. e5.0.0-beta.6
  15. options:
  16. -h|--help: Print this usage.
  17. -b|--base: Specify the current release base branch, can be one of
  18. release-50
  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. --docker-latest: Set this option to assign :latest tag on the corresponding docker image
  26. in addition to regular :<version> one
  27. NOTE: For 5.0 series the current working branch must be 'release-50' for opensource edition
  28. and 'release-e50' for enterprise edition.
  29. --.--[ master ]---------------------------.-----------.---
  30. \\ /
  31. \`---[release-50]----(v5.0.12 | e5.0.0)
  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. DOCKER_LATEST_TAG=
  45. case "$TAG" in
  46. v*)
  47. TAG_PREFIX='v'
  48. PROFILE='emqx'
  49. SKIP_APPUP='yes'
  50. DOCKER_LATEST_TAG='docker-latest-ce'
  51. ;;
  52. e*)
  53. TAG_PREFIX='e'
  54. PROFILE='emqx-enterprise'
  55. #TODO change to no when we are ready to support hot-upgrade
  56. SKIP_APPUP='yes'
  57. DOCKER_LATEST_TAG='docker-latest-ee'
  58. ;;
  59. -h|--help)
  60. usage
  61. exit 0
  62. ;;
  63. *)
  64. logerr "Unknown version tag $TAG"
  65. usage
  66. exit 1
  67. ;;
  68. esac
  69. shift 1
  70. DRYRUN='no'
  71. DOCKER_LATEST='no'
  72. while [ "$#" -gt 0 ]; do
  73. case $1 in
  74. -h|--help)
  75. usage
  76. exit 0
  77. ;;
  78. --skip-appup)
  79. shift
  80. SKIP_APPUP='yes'
  81. ;;
  82. --dryrun)
  83. shift
  84. DRYRUN='yes'
  85. ;;
  86. -b|--base)
  87. BASE_BR="${2:-}"
  88. if [ -z "${BASE_BR}" ]; then
  89. logerr "Must specify which base branch"
  90. exit 1
  91. fi
  92. shift 2
  93. ;;
  94. --prev-tag)
  95. shift
  96. PREV_TAG="$1"
  97. shift
  98. ;;
  99. --docker-latest)
  100. DOCKER_LATEST='yes'
  101. shift
  102. ;;
  103. *)
  104. logerr "Unknown option $1"
  105. exit 1
  106. ;;
  107. esac
  108. done
  109. rel_branch() {
  110. local tag="$1"
  111. case "$tag" in
  112. v5.0.*)
  113. echo 'release-50'
  114. ;;
  115. e5.0.*)
  116. echo 'release-50'
  117. ;;
  118. *)
  119. logerr "Unsupported version tag $TAG"
  120. exit 1
  121. ;;
  122. esac
  123. }
  124. ## Ensure the current work branch
  125. assert_work_branch() {
  126. local tag="$1"
  127. local release_branch
  128. release_branch="$(rel_branch "$tag")"
  129. local base_branch
  130. base_branch="${BASE_BR:-$(git branch --show-current)}"
  131. if [ "$base_branch" != "$release_branch" ]; then
  132. logerr "Base branch: $base_branch"
  133. logerr "Relase tag must be on the release branch: $release_branch"
  134. logerr "or must use -b|--base option to specify which release branch is current branch based on"
  135. exit 1
  136. fi
  137. }
  138. assert_work_branch "$TAG"
  139. ## Ensure no dirty changes
  140. assert_not_dirty() {
  141. local diff
  142. diff="$(git diff --name-only)"
  143. if [ -n "$diff" ]; then
  144. logerr "Git status is not clean? Changed files:"
  145. logerr "$diff"
  146. exit 1
  147. fi
  148. }
  149. assert_not_dirty
  150. ## Assert that the tag is not already created
  151. assert_tag_absent() {
  152. local tag="$1"
  153. ## Fail if the tag already exists
  154. EXISTING="$(git tag --list "$tag")"
  155. if [ -n "$EXISTING" ]; then
  156. logerr "$tag already released?"
  157. logerr 'This script refuse to force re-tag.'
  158. logerr 'If re-tag is intended, you must first delete the tag from both local and remote'
  159. exit 1
  160. fi
  161. }
  162. assert_tag_absent "$TAG"
  163. PKG_VSN=$(./pkg-vsn.sh "$PROFILE")
  164. ## Assert package version is updated to the tag which is being created
  165. assert_release_version() {
  166. local tag="$1"
  167. # shellcheck disable=SC2001
  168. pkg_vsn="$(echo "$PKG_VSN" | sed 's/-g[0-9a-f]\{8\}$//g')"
  169. if [ "${TAG_PREFIX}${pkg_vsn}" != "${tag}" ]; then
  170. logerr "The release version ($pkg_vsn) is different from the desired git tag."
  171. logerr "Update the release version in emqx_release.hrl"
  172. exit 1
  173. fi
  174. }
  175. assert_release_version "$TAG"
  176. ## Check if all upstream branches are merged
  177. SYNC_REMOTES_ARGS=
  178. [ -n "${BASE_BR:-}" ] && SYNC_REMOTES_ARGS="--base $BASE_BR $SYNC_REMOTES_ARGS"
  179. [ "$DRYRUN" = 'yes' ] && SYNC_REMOTES_ARGS="--dryrun $SYNC_REMOTES_ARGS"
  180. # shellcheck disable=SC2086
  181. ./scripts/rel/sync-remotes.sh $SYNC_REMOTES_ARGS
  182. ## Check if the Chart versions are in sync
  183. ./scripts/rel/check-chart-vsn.sh "$PROFILE"
  184. ## Check if app versions are bumped
  185. ./scripts/apps-version-check.sh
  186. ## Ensure appup files are updated
  187. if [ "$SKIP_APPUP" = 'no' ]; then
  188. logmsg "Checking appups"
  189. ./scripts/update-appup.sh "$PROFILE" --check
  190. else
  191. logmsg "Skipped checking appup updates"
  192. fi
  193. ## Ensure relup paths are updated
  194. ## TODO: add relup path db
  195. #./scripts/relup-base-vsns.escript check-vsn-db "$PKG_VSN" "$RELUP_PATHS"
  196. ## Run some additional checks (e.g. some for enterprise edition only)
  197. CHECKS_DIR="./scripts/rel/checks"
  198. if [ -d "${CHECKS_DIR}" ]; then
  199. CHECKS="$(find "${CHECKS_DIR}" -name "*.sh" -print0 2>/dev/null | xargs -0)"
  200. for c in $CHECKS; do
  201. logmsg "Executing $c"
  202. $c
  203. done
  204. fi
  205. generate_changelog () {
  206. local from_tag="${PREV_TAG:-}"
  207. if [[ -z $from_tag ]]; then
  208. if [ $PROFILE == "emqx" ]; then
  209. from_tag="$(git describe --tags --abbrev=0 --match 'v*')"
  210. else
  211. from_tag="$(git describe --tags --abbrev=0 --match 'e*')"
  212. fi
  213. fi
  214. ./scripts/rel/format-changelog.sh -b "${from_tag}" -l 'en' -v "$TAG" > "changes/${TAG}.en.md"
  215. ./scripts/rel/format-changelog.sh -b "${from_tag}" -l 'zh' -v "$TAG" > "changes/${TAG}.zh.md"
  216. git add changes/"${TAG}".*.md
  217. [ -n "$(git status -s)" ] && git commit -m "chore: Generate changelog for ${TAG}"
  218. }
  219. if [ "$DRYRUN" = 'yes' ]; then
  220. logmsg "Release tag is ready to be created with command: git tag $TAG"
  221. if [ "$DOCKER_LATEST" = 'yes' ]; then
  222. logmsg "Docker latest tag is ready to be created with command: git tag --force $DOCKER_LATEST_TAG"
  223. fi
  224. else
  225. case "$TAG" in
  226. *rc*)
  227. true
  228. ;;
  229. *alpha*)
  230. true
  231. ;;
  232. *beta*)
  233. true
  234. ;;
  235. e5.0.0*)
  236. # the first release has no change log
  237. true
  238. ;;
  239. *)
  240. generate_changelog
  241. ;;
  242. esac
  243. git tag "$TAG"
  244. logmsg "$TAG is created OK."
  245. if [ "$DOCKER_LATEST" = 'yes' ]; then
  246. git tag --force "$DOCKER_LATEST_TAG"
  247. logmsg "$DOCKER_LATEST_TAG is created OK."
  248. fi
  249. logwarn "Don't forget to push the tags!"
  250. if [ "$DOCKER_LATEST" = 'yes' ]; then
  251. echo "git push --atomic --force origin $TAG $DOCKER_LATEST_TAG"
  252. else
  253. echo "git push origin $TAG"
  254. fi
  255. fi