apps-version-check.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. set -euo pipefail
  3. remote="refs/remote/$(git remote -v | grep fetch | grep 'emqx/emqx' | awk '{print $1}')"
  4. latest_release=$(git describe --tags "$(git rev-list --tags --max-count=1 --remotes="$remote")")
  5. bad_app_count=0
  6. get_vsn() {
  7. commit="$1"
  8. app_src_file="$2"
  9. if [ "$commit" = 'HEAD' ]; then
  10. if [ -f "$app_src_file" ]; then
  11. grep vsn "$app_src_file" | grep -oE '"[0-9]+.[0-9]+.[0-9]+"' | tr -d '"' || true
  12. fi
  13. else
  14. git show "$commit":"$app_src_file" 2>/dev/null | grep vsn | grep -oE '"[0-9]+.[0-9]+.[0-9]+"' | tr -d '"' || true
  15. fi
  16. }
  17. while read -r app_path; do
  18. app=$(basename "$app_path")
  19. src_file="$app_path/src/$app.app.src"
  20. old_app_version="$(get_vsn "$latest_release" "$src_file")"
  21. ## TODO: delete it after new version is released with emqx app in apps dir
  22. if [ "$app" = 'emqx' ] && [ "$old_app_version" = '' ]; then
  23. old_app_version="$(get_vsn "$latest_release" 'src/emqx.app.src')"
  24. fi
  25. now_app_version="$(get_vsn 'HEAD' "$src_file")"
  26. ## TODO: delete it after new version is released with emqx app in apps dir
  27. if [ "$app" = 'emqx' ] && [ "$now_app_version" = '' ]; then
  28. now_app_version="$(get_vsn 'HEAD' 'src/emqx.app.src')"
  29. fi
  30. if [ -z "$now_app_version" ]; then
  31. echo "failed_to_get_new_app_vsn for $app"
  32. exit 1
  33. fi
  34. if [ -z "${old_app_version:-}" ]; then
  35. echo "skiped checking new app ${app}"
  36. elif [ "$old_app_version" = "$now_app_version" ]; then
  37. lines="$(git diff --name-only "$latest_release"...HEAD \
  38. -- "$app_path/src" \
  39. -- "$app_path/priv" \
  40. -- "$app_path/c_src")"
  41. if [ "$lines" != '' ]; then
  42. echo "$src_file needs a vsn bump (old=$old_app_version)"
  43. echo "changed: $lines"
  44. bad_app_count=$(( bad_app_count + 1))
  45. fi
  46. fi
  47. done < <(./scripts/find-apps.sh)
  48. if [ $bad_app_count -gt 0 ]; then
  49. exit 1
  50. else
  51. echo "apps version check successfully"
  52. fi