update-appup.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env bash
  2. ## This script wrapps update_appup.escript,
  3. ## it provides a more commonly used set of default args.
  4. ## Arg1: EMQX PROFILE
  5. set -euo pipefail
  6. set -x
  7. usage() {
  8. echo "$0 PROFILE"
  9. }
  10. # ensure dir
  11. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
  12. PROFILE="${1:-}"
  13. GIT_REPO='emqx/emqx.git'
  14. case "$PROFILE" in
  15. emqx-enterprise)
  16. TAG_PREFIX='e'
  17. ;;
  18. emqx)
  19. TAG_PREFIX='v'
  20. ;;
  21. *)
  22. echo "Unknown profile $PROFILE"
  23. usage
  24. exit 1
  25. ;;
  26. esac
  27. ## possible tags:
  28. ## v4.3.11
  29. ## e4.3.11
  30. ## rel-v4.4.3
  31. ## rel-e4.4.3
  32. PREV_TAG="${PREV_TAG:-$(git describe --tag --abbrev=0 --match "[${TAG_PREFIX}|rel-]*" --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*')}"
  33. shift 1
  34. # bash 3.2 treat empty array as unbound, so we can't use 'ESCRIPT_ARGS=()' here,
  35. # but must add an empty-string element to the array
  36. ESCRIPT_ARGS=( '' )
  37. while [ "$#" -gt 0 ]; do
  38. case $1 in
  39. -h|--help)
  40. help
  41. exit 0
  42. ;;
  43. --skip-build)
  44. SKIP_BUILD='yes'
  45. shift
  46. ;;
  47. --skip-build-base)
  48. SKIP_BUILD_BASE='yes'
  49. shift
  50. ;;
  51. --check)
  52. # hijack the --check option
  53. IS_CHECK='yes'
  54. shift
  55. ;;
  56. *)
  57. ESCRIPT_ARGS+=( "$1" )
  58. shift
  59. ;;
  60. esac
  61. done
  62. if [ "$TAG_PREFIX" = 'v' ]; then
  63. SRC_DIRS="{apps}"
  64. else
  65. SRC_DIRS="{apps,lib-ee}"
  66. fi
  67. ## make sure we build here in bash and always pass --skip-build to escript
  68. if [ "${SKIP_BUILD:-}" != 'yes' ]; then
  69. make "${PROFILE}"
  70. fi
  71. PREV_DIR_BASE="/tmp/_w"
  72. mkdir -p "${PREV_DIR_BASE}"
  73. if [ ! -d "${PREV_DIR_BASE}/${PREV_TAG}" ]; then
  74. cp -R . "${PREV_DIR_BASE}/${PREV_TAG}"
  75. # always 'yes' in CI
  76. NEW_COPY='yes'
  77. else
  78. NEW_COPY='no'
  79. fi
  80. if [ "${SKIP_BUILD_BASE:-no}" = 'yes' ]; then
  81. echo "not building relup base ${PREV_DIR_BASE}/${PREV_TAG}"
  82. else
  83. pushd "${PREV_DIR_BASE}/${PREV_TAG}"
  84. if [ "$NEW_COPY" = 'no' ]; then
  85. REMOTE="$(git remote -v | grep "${GIT_REPO}" | head -1 | awk '{print $1}')"
  86. git fetch "$REMOTE"
  87. fi
  88. git reset --hard
  89. git clean -ffdx
  90. git checkout "${PREV_TAG}"
  91. make "$PROFILE"
  92. popd
  93. fi
  94. PREV_REL_DIR="${PREV_DIR_BASE}/${PREV_TAG}/_build/${PROFILE}/lib"
  95. # bash 3.2 does not allow empty array, so we had to add an empty string in the ESCRIPT_ARGS array,
  96. # this in turn makes quoting "${ESCRIPT_ARGS[@]}" problematic, hence disable SC2068 check here
  97. # shellcheck disable=SC2068
  98. ./scripts/update_appup.escript \
  99. --src-dirs "${SRC_DIRS}/**" \
  100. --release-dir "_build/${PROFILE}/lib" \
  101. --prev-release-dir "${PREV_REL_DIR}" \
  102. --skip-build \
  103. ${ESCRIPT_ARGS[@]} "$PREV_TAG"
  104. if [ "${IS_CHECK:-}" = 'yes' ]; then
  105. diffs="$(git diff --name-only | grep -E '\.appup\.src' || true)"
  106. if [ "$diffs" != '' ]; then
  107. git --no-pager diff
  108. echo "$0 ---check produced git diff"
  109. exit 1
  110. fi
  111. fi