apps-version-check.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # ensure dir
  4. cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
  5. # match any official release tag 'e*' and 'v*'
  6. latest_release="$(env PREV_TAG_MATCH_PATTERN='*' ./scripts/find-prev-rel-tag.sh)"
  7. echo "Version check compare base: $latest_release"
  8. bad_app_count=0
  9. no_comment_re='(^[^\s?%])'
  10. ## TODO: c source code comments re (in $app_path/c_src dirs)
  11. parse_semver() {
  12. echo "$1" | tr '.|-' ' '
  13. }
  14. APPS="$(./scripts/find-apps.sh)"
  15. for app in ${APPS}; do
  16. if [ "$app" != "emqx" ]; then
  17. app_path="$app"
  18. else
  19. app_path="."
  20. fi
  21. src_file="$app_path/src/$(basename "$app").app.src"
  22. if git show "$latest_release":"$src_file" >/dev/null 2>&1; then
  23. old_app_version="$(git show "$latest_release":"$src_file" | grep vsn | grep -oE '"[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"')"
  24. else
  25. old_app_version='not_found'
  26. fi
  27. now_app_version=$(grep -E 'vsn' "$src_file" | grep -oE '"[0-9]+\.[0-9]+\.[0-9]+"' | tr -d '"')
  28. if [ "$old_app_version" = 'not_found' ]; then
  29. echo "IGNORE: $src_file is newly added"
  30. true
  31. elif [ "$old_app_version" = "$now_app_version" ]; then
  32. changed_lines="$(git diff "$latest_release" --ignore-blank-lines -G "$no_comment_re" \
  33. -- "$app_path/src" \
  34. -- "$app_path/include" \
  35. -- ":(exclude)"$app_path/src/*.appup.src"" \
  36. -- "$app_path/priv" \
  37. -- "$app_path/c_src" | wc -l ) "
  38. if [ "$changed_lines" -gt 0 ]; then
  39. echo "ERROR: $src_file needs a vsn bump"
  40. bad_app_count=$(( bad_app_count + 1))
  41. fi
  42. else
  43. # shellcheck disable=SC2207
  44. old_app_version_semver=($(parse_semver "$old_app_version"))
  45. # shellcheck disable=SC2207
  46. now_app_version_semver=($(parse_semver "$now_app_version"))
  47. if [ "${old_app_version_semver[0]}" = "${now_app_version_semver[0]}" ] && \
  48. [ "${old_app_version_semver[1]}" = "${now_app_version_semver[1]}" ] && \
  49. [ "$(( old_app_version_semver[2] + 1 ))" = "${now_app_version_semver[2]}" ]; then
  50. true
  51. elif [ "${old_app_version_semver[0]}" = "${now_app_version_semver[0]}" ] && \
  52. [ "$(( old_app_version_semver[1] + 1 ))" = "${now_app_version_semver[1]}" ] && \
  53. [ "${now_app_version_semver[2]}" = "0" ]; then
  54. true
  55. else
  56. echo "$src_file: non-strict semver version bump from $old_app_version to $now_app_version"
  57. bad_app_count=$(( bad_app_count + 1))
  58. fi
  59. fi
  60. done
  61. if [ $bad_app_count -gt 0 ]; then
  62. exit 1
  63. else
  64. echo "apps version check successfully"
  65. fi