update-appup.sh 3.0 KB

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