find-apps.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. CE="$(find_app 'apps')"
  38. EE="$(find_app 'lib-ee')"
  39. APPS_ALL="$(echo -e "${CE}\n${EE}")"
  40. if [ "$MODE" = 'list' ]; then
  41. echo "${APPS_ALL}"
  42. exit 0
  43. fi
  44. ##################################################
  45. ###### now deal with the github action's matrix.
  46. ##################################################
  47. format_app_entry() {
  48. local groups="$2"
  49. local group=0
  50. while [ "$groups" -gt $group ]; do
  51. if [ $group -gt 0 ]; then
  52. echo ", "
  53. fi
  54. group=$(( group + 1 ))
  55. ## prefix is for github actions (they don't like slash in variables)
  56. local prefix=${1//\//_}
  57. echo -n -e "$(
  58. cat <<END
  59. {"app": "${1}", "suitegroup": "${group}_${groups}", "profile": "${3}", "runner": "${4}", "prefix": "${prefix}"}
  60. END
  61. )"
  62. done
  63. }
  64. matrix() {
  65. local runner
  66. local profile
  67. local entries=()
  68. for app in ${APPS_ALL}; do
  69. if [ -f "${app}/docker-ct" ]; then
  70. runner="docker"
  71. else
  72. runner="host"
  73. fi
  74. case "${app}" in
  75. apps/emqx)
  76. entries+=("$(format_app_entry "$app" 5 emqx "$runner")")
  77. entries+=("$(format_app_entry "$app" 5 emqx-enterprise "$runner")")
  78. ;;
  79. apps/emqx_bridge)
  80. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  81. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  82. ;;
  83. apps/emqx_connector)
  84. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  85. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  86. ;;
  87. apps/emqx_dashboard)
  88. entries+=("$(format_app_entry "$app" 1 emqx "$runner")")
  89. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  90. ;;
  91. apps/*)
  92. if [[ -f "${app}/BSL.txt" ]]; then
  93. profile='emqx-enterprise'
  94. else
  95. profile='emqx'
  96. fi
  97. entries+=("$(format_app_entry "$app" 1 "$profile" "$runner")")
  98. ;;
  99. lib-ee/*)
  100. entries+=("$(format_app_entry "$app" 1 emqx-enterprise "$runner")")
  101. ;;
  102. *)
  103. echo "unknown app: $app"
  104. exit 1
  105. ;;
  106. esac
  107. done
  108. echo -n "[$(IFS=,; echo "${entries[*]}")]"
  109. }
  110. matrix