2
0

CheckPreviewEnvLocal.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env bash
  2. env_file_path="docker/.env"
  3. ngrok_url=""
  4. command -v ngrok >/dev/null 2>&1 || { echo "[ERROR] ngrok is required to test Preview Environments locally" >&2; exit 1; }
  5. if [ -f "$env_file_path" ]; then
  6. env_vars="$(cat "$env_file_path" | grep -v "^#" | sed -r "/^\s*$/d" | sed "s/\#.*//")"
  7. IFS="="
  8. serverURLSet=0
  9. githubAppClientIDSet=0
  10. githubAppClientSecretSet=0
  11. githubAppWebhookSecretSet=0
  12. githubAppNameSet=0
  13. githubAppIDSet=0
  14. githubAppSecretPathSet=0
  15. githubIncomingWebhookSecretSet=0
  16. while read -r k v; do
  17. if [[ "$k" == "SERVER_URL" ]]; then
  18. if [[ "$v" != *"ngrok.io"* ]]; then
  19. echo "[ERROR] SERVER_URL must be set to an ngrok.io URL."
  20. exit 1
  21. fi
  22. serverURLSet=1
  23. ngrok_url="$v"
  24. elif [[ "$k" == "GITHUB_APP_CLIENT_ID" ]]; then
  25. githubAppClientIDSet=1
  26. elif [[ "$k" == "GITHUB_APP_CLIENT_SECRET" ]]; then
  27. githubAppClientSecretSet=1
  28. elif [[ "$k" == "GITHUB_APP_WEBHOOK_SECRET" ]]; then
  29. githubAppWebhookSecretSet=1
  30. elif [[ "$k" == "GITHUB_APP_NAME" ]]; then
  31. githubAppNameSet=1
  32. elif [[ "$k" == "GITHUB_APP_ID" ]]; then
  33. githubAppIDSet=1
  34. elif [[ "$k" == "GITHUB_APP_SECRET_PATH" ]]; then
  35. githubAppSecretPathSet=1
  36. elif [[ "$k" == "GITHUB_INCOMING_WEBHOOK_SECRET" ]]; then
  37. githubIncomingWebhookSecretSet=1
  38. fi
  39. done <<< "$env_vars"
  40. if [[ "$serverURLSet" == "0" ]]; then
  41. echo "[ERROR] SERVER_URL must be set to an ngrok.io URL."
  42. exit 1
  43. elif [[ "$githubAppClientIDSet" == 0 ]]; then
  44. echo "[ERROR] GITHUB_APP_CLIENT_ID must be set"
  45. exit 1
  46. elif [[ "$githubAppClientSecretSet" == 0 ]]; then
  47. echo "[ERROR] GITHUB_APP_CLIENT_SECRET must be set"
  48. exit 1
  49. elif [[ "$githubAppWebhookSecretSet" == 0 ]]; then
  50. echo "[ERROR] GITHUB_APP_WEBHOOK_SECRET must be set"
  51. exit 1
  52. elif [[ "$githubAppNameSet" == 0 ]]; then
  53. echo "[ERROR] GITHUB_APP_NAME must be set"
  54. exit 1
  55. elif [[ "$githubAppIDSet" == 0 ]]; then
  56. echo "[ERROR] GITHUB_APP_ID must be set"
  57. exit 1
  58. elif [[ "$githubAppSecretPathSet" == 0 ]]; then
  59. echo "[ERROR] GITHUB_APP_SECRET_PATH must be set"
  60. exit 1
  61. elif [[ "$githubIncomingWebhookSecretSet" == 0 ]]; then
  62. echo "[ERROR] GITHUB_INCOMING_WEBHOOK_SECRET must be set"
  63. exit 1
  64. fi
  65. else
  66. echo "[ERROR] docker/.env should be set with the required variables"
  67. exit 1
  68. fi
  69. echo "[SUCCESS] All required variables are set. MAKE SURE your GitHub app has all URLs set to $ngrok_url."