find-apps.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # ensure dir
  4. cd -P -- "$(dirname -- "$0")/.."
  5. help() {
  6. echo
  7. echo "-h|--help: To display this usage info"
  8. echo "--ci: Print apps in json format for github ci matrix"
  9. }
  10. MODE='list'
  11. while [ "$#" -gt 0 ]; do
  12. case $1 in
  13. -h|--help)
  14. help
  15. exit 0
  16. ;;
  17. --ci)
  18. MODE='ci'
  19. shift 1
  20. ;;
  21. *)
  22. echo "unknown option $1"
  23. exit 1
  24. ;;
  25. esac
  26. done
  27. if [ "$(./scripts/get-distro.sh)" = 'windows' ]; then
  28. # Otherwise windows may resolve to find.exe
  29. FIND="/usr/bin/find"
  30. else
  31. FIND='find'
  32. fi
  33. find_app() {
  34. local appdir="$1"
  35. "$FIND" "${appdir}" -mindepth 1 -maxdepth 1 -type d
  36. }
  37. APPS_ALL="$(find_app 'apps')"
  38. if [ "$MODE" = 'list' ]; then
  39. echo "${APPS_ALL}"
  40. exit 0
  41. fi
  42. ##################################################
  43. ###### now deal with the github action's matrix.
  44. ##################################################
  45. format_app_entry() {
  46. local groups="$2"
  47. local group=0
  48. while [ "$groups" -gt $group ]; do
  49. if [ $group -gt 0 ]; then
  50. echo ", "
  51. fi
  52. group=$(( group + 1 ))
  53. ## prefix is for github actions (they don't like slash in variables)
  54. local prefix=${1//\//_}
  55. echo -n -e "$(
  56. cat <<END
  57. {"app": "${1}", "suitegroup": "${group}_${groups}", "profile": "${3}", "runner": "${4}", "prefix": "${prefix}"}
  58. END
  59. )"
  60. done
  61. }
  62. matrix() {
  63. local runner
  64. local profile
  65. local entries=()
  66. for app in ${APPS_ALL}; do
  67. if [ -f "${app}/docker-ct" ]; then
  68. runner="docker"
  69. else
  70. runner="host"
  71. fi
  72. case "${app}" in
  73. apps/emqx)
  74. entries+=("$(format_app_entry "$app" 8 emqx "$runner")")
  75. entries+=("$(format_app_entry "$app" 8 emqx-enterprise "$runner")")
  76. ;;
  77. apps/emqx_bridge)
  78. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  79. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  80. ;;
  81. apps/emqx_connector)
  82. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  83. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  84. ;;
  85. apps/emqx_dashboard)
  86. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  87. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  88. ;;
  89. apps/emqx_prometheus)
  90. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  91. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  92. ;;
  93. apps/emqx_rule_engine)
  94. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  95. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  96. ;;
  97. apps/emqx_management)
  98. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  99. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  100. ;;
  101. apps/emqx_auth_http)
  102. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  103. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  104. ;;
  105. apps/*)
  106. if [[ -f "${app}/BSL.txt" ]]; then
  107. profile='emqx-enterprise'
  108. else
  109. profile='emqx'
  110. fi
  111. entries+=("$(format_app_entry "$app" 1 "$profile" "$runner")")
  112. ;;
  113. *)
  114. echo "unknown app: $app"
  115. exit 1
  116. ;;
  117. esac
  118. done
  119. echo -n "[$(IFS=,; echo "${entries[*]}")]"
  120. }
  121. matrix