#!/usr/bin/env bash
#
# Version 1.1
# - Moved to .ci folder and seperated out `run-repository.sh`
# - Add `$RUNSCRIPTS` env var for running Elasticsearch dependent products

# Default environment variables
export STACK_VERSION="${STACK_VERSION:=8.0.0-SNAPSHOT}"
export TEST_SUITE="${TEST_SUITE:=platinum}"
export PYTHON_VERSION="${PYTHON_VERSION:=3.14}"
export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=urllib3}"
export ES_YAML_TESTS_BRANCH="${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
if [[ ! -n "$ES_YAML_TESTS_BRANCH" ]]; then
    export ES_YAML_TESTS_BRANCH="${BUILDKITE_BRANCH}"
fi

script_path=$(dirname $(realpath $0))
source $script_path/functions/imports.sh
set -euo pipefail

echo "--- :elasticsearch: Starting Elasticsearch"
DETACH=true bash $script_path/run-elasticsearch.sh

if [[ -n "$RUNSCRIPTS" ]]; then
  for RUNSCRIPT in ${RUNSCRIPTS//,/ }; do
    echo -e "\033[1m>>>>> Running run-$RUNSCRIPT.sh >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
    CONTAINER_NAME=${RUNSCRIPT} \
      DETACH=true \
      bash $script_path/run-${RUNSCRIPT}.sh
  done
fi

echo "+++ :python: Client tests"
bash $script_path/run-repository.sh
