find-apps.sh 2.3 KB

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