find-apps.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_description() {
  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. describe_app() {
  65. app="$1"
  66. local runner="host"
  67. local profile
  68. if [ -f "${app}/docker-ct" ]; then
  69. runner="docker"
  70. fi
  71. case "${app}" in
  72. apps/*)
  73. if [[ -f "${app}/BSL.txt" ]]; then
  74. profile='emqx-enterprise'
  75. else
  76. profile='emqx'
  77. fi
  78. ;;
  79. lib-ee/*)
  80. profile='emqx-enterprise'
  81. ;;
  82. *)
  83. echo "unknown app: $app"
  84. exit 1
  85. ;;
  86. esac
  87. if [[ "$app" == "apps/emqx" ]]; then
  88. suitegroups=5
  89. else
  90. suitegroups=1
  91. fi
  92. format_app_description "$app" "$suitegroups" "$profile" "$runner"
  93. }
  94. matrix() {
  95. local sep='['
  96. for app in ${APPS_ALL}; do
  97. row="$(describe_app "$app")"
  98. if [ -z "$row" ]; then
  99. continue
  100. fi
  101. echo -n "${sep}${row}"
  102. sep=', '
  103. done
  104. echo ']'
  105. }
  106. matrix