find-apps.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. ## prefix is for github actions (they don't like slash in variables)
  49. local prefix=${1//\//_}
  50. echo -n -e "$(
  51. cat <<END
  52. {"app": "${1}", "profile": "${2}", "runner": "${3}", "prefix": "${prefix}"}
  53. END
  54. )"
  55. }
  56. describe_app() {
  57. app="$1"
  58. local runner="host"
  59. local profile
  60. if [ -f "${app}/docker-ct" ]; then
  61. runner="docker"
  62. fi
  63. case "${app}" in
  64. apps/*)
  65. profile='emqx'
  66. ;;
  67. lib-ee/*)
  68. profile='emqx-enterprise'
  69. ;;
  70. *)
  71. echo "unknown app: $app"
  72. exit 1
  73. ;;
  74. esac
  75. format_app_description "$app" "$profile" "$runner"
  76. }
  77. matrix() {
  78. local sep='['
  79. for app in ${APPS_ALL}; do
  80. row="$(describe_app "$app")"
  81. if [ -z "$row" ]; then
  82. continue
  83. fi
  84. echo -n "${sep}${row}"
  85. sep=', '
  86. done
  87. echo ']'
  88. }
  89. matrix