find-apps.sh 1.9 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 fast|docker: Print apps in json format for github ci mtrix"
  9. }
  10. CI='novalue'
  11. while [ "$#" -gt 0 ]; do
  12. case $1 in
  13. -h|--help)
  14. help
  15. exit 0
  16. ;;
  17. --ci)
  18. CI="$2"
  19. shift 2
  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 [ "$CI" = 'novalue' ]; then
  41. echo "${APPS_ALL}"
  42. exit 0
  43. fi
  44. ##################################################
  45. ###### now deal with the github action's matrix.
  46. ##################################################
  47. dimensions() {
  48. app="$1"
  49. if [ -f "${app}/docker-ct" ]; then
  50. if [[ "$CI" != 'docker' ]]; then
  51. return
  52. fi
  53. else
  54. if [[ "$CI" != 'fast' ]]; then
  55. return
  56. fi
  57. fi
  58. case "${app}" in
  59. apps/*)
  60. profile='emqx'
  61. ;;
  62. lib-ee/*)
  63. profile='emqx-enterprise'
  64. ;;
  65. *)
  66. echo "unknown app: $app"
  67. exit 1
  68. ;;
  69. esac
  70. ## poor-man's json formatter
  71. echo -n -e "[\"$app\", \"$profile\"]"
  72. }
  73. matrix() {
  74. first_row='yes'
  75. for app in ${APPS_ALL}; do
  76. row="$(dimensions "$app")"
  77. if [ -z "$row" ]; then
  78. continue
  79. fi
  80. if [ "$first_row" = 'yes' ]; then
  81. first_row='no'
  82. echo -n "$row"
  83. else
  84. echo -n ",${row}"
  85. fi
  86. done
  87. }
  88. echo -n '['
  89. matrix
  90. echo ']'