1- # Common setup function for both web and mobile
1+ #! /usr/bin/env bash
2+ # shellcheck shell=bash
3+
24setup_environment () {
35 local setup_type=$1 # "web" or "mobile"
46 local tech_stack=$2
57 local max_parallels
6- local setup_function
78
89 log_section " 📦 Project Setup"
910
@@ -19,8 +20,6 @@ setup_environment() {
1920 log_msg_to " Starting ${setup_type} setup for $TECH_STACK " " $NOW_RUN_LOG_FILE "
2021
2122 local local_flag=false
22- local attempt=1
23- local run_status=1
2423
2524 # Calculate parallels
2625 local total_parallels
@@ -36,19 +35,19 @@ setup_environment() {
3635 java)
3736 " setup_${setup_type} _java" " $local_flag " " $parallels_per_platform " " $NOW_RUN_LOG_FILE "
3837 log_section " ✅ Results"
39- run_status= $( identify_run_status_java " $NOW_RUN_LOG_FILE " )
38+ identify_run_status_java " $NOW_RUN_LOG_FILE "
4039 check_return_value $? " $NOW_RUN_LOG_FILE " " ${setup_type} setup succeeded." " ❌ ${setup_type} setup failed. Check $log_file for details"
4140 ;;
4241 python)
4342 " setup_${setup_type} _python" " $local_flag " " $parallels_per_platform " " $NOW_RUN_LOG_FILE "
4443 log_section " ✅ Results"
45- run_status= $( identify_run_status_python " $NOW_RUN_LOG_FILE " )
44+ identify_run_status_python " $NOW_RUN_LOG_FILE "
4645 check_return_value $? " $NOW_RUN_LOG_FILE " " ${setup_type} setup succeeded." " ❌ ${setup_type} setup failed. Check $log_file for details"
4746 ;;
4847 nodejs)
4948 " setup_${setup_type} _nodejs" " $local_flag " " $parallels_per_platform " " $NOW_RUN_LOG_FILE "
5049 log_section " ✅ Results"
51- run_status= $( identify_run_status_nodejs " $NOW_RUN_LOG_FILE " )
50+ identify_run_status_nodejs " $NOW_RUN_LOG_FILE "
5251 check_return_value $? " $NOW_RUN_LOG_FILE " " ${setup_type} setup succeeded." " ❌ ${setup_type} setup failed. Check $log_file for details"
5352 ;;
5453 * )
@@ -67,7 +66,7 @@ setup_web_java() {
6766
6867 mkdir -p " $WORKSPACE_DIR /$PROJECT_FOLDER "
6968
70- clone_repository $REPO $TARGET_DIR
69+ clone_repository " $REPO " " $TARGET_DIR "
7170
7271 cd " $TARGET_DIR " || return 1
7372
101100 # === 6️⃣ Build and Run ===
102101 log_msg_to " ⚙️ Running 'mvn install -DskipTests'"
103102 log_info " Installing dependencies"
104- mvn install -DskipTests >> $NOW_RUN_LOG_FILE 2>&1 || return 1
103+ mvn install -DskipTests >> " $NOW_RUN_LOG_FILE " 2>&1 || return 1
105104 log_success " Dependencies installed"
106105
107106
@@ -115,13 +114,13 @@ EOF
115114
116115 print_tests_running_log_section " mvn test -P sample-test"
117116 log_msg_to " 🚀 Running 'mvn test -P sample-test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
118- mvn test -P sample-test >> $NOW_RUN_LOG_FILE 2>&1 &
117+ mvn test -P sample-test >> " $NOW_RUN_LOG_FILE " 2>&1 &
119118 cmd_pid=$! || return 1
120119
121120 show_spinner " $cmd_pid "
122121 wait " $cmd_pid "
123122
124- cd " $WORKSPACE_DIR /$PROJECT_FOLDER "
123+ cd " $WORKSPACE_DIR /$PROJECT_FOLDER " || return 1
125124 return 0
126125}
127126
@@ -138,9 +137,9 @@ setup_app_java() {
138137 clone_repository $REPO $TARGET_DIR
139138
140139 if [[ " $APP_PLATFORM " == " all" || " $APP_PLATFORM " == " android" ]]; then
141- cd android/testng-examples
140+ cd " android/testng-examples" || return 1
142141 else
143- cd ios/testng-examples
142+ cd ios/testng-examples || return 1
144143 fi
145144
146145
162161 # Run Maven install first
163162 log_msg_to " ⚙️ Running 'mvn clean'"
164163 log_info " Installing dependencies"
165- if ! mvn clean >> $NOW_RUN_LOG_FILE 2>&1 ; then
164+ if ! mvn clean >> " $NOW_RUN_LOG_FILE " 2>&1 ; then
166165 log_msg_to " ❌ 'mvn clean' FAILED. See $log_file for details."
167166 return 1 # Fail the function if clean fails
168167 fi
177176
178177 log_msg_to " 🚀 Running 'mvn test -P sample-test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
179178 print_tests_running_log_section " mvn test -P sample-test"
180- mvn test -P sample-test >> $NOW_RUN_LOG_FILE 2>&1 &
179+ mvn test -P sample-test >> " $NOW_RUN_LOG_FILE " 2>&1 &
181180 cmd_pid=$! || return 1
182181
183182 show_spinner " $cmd_pid "
@@ -195,11 +194,11 @@ setup_web_python() {
195194 REPO=" browserstack-examples-pytest"
196195 TARGET_DIR=" $WORKSPACE_DIR /$PROJECT_FOLDER /$REPO "
197196
198- clone_repository $REPO $TARGET_DIR
197+ clone_repository " $REPO " " $TARGET_DIR "
199198
200199 detect_setup_python_env
201200
202- pip3 install -r requirements.txt >> $NOW_RUN_LOG_FILE 2>&1
201+ pip3 install -r requirements.txt >> " $NOW_RUN_LOG_FILE " 2>&1
203202 log_success " Dependencies installed"
204203
205204 # Update YAML at root level (browserstack.yml)
301300 )
302301
303302 deactivate
304- cd " $WORKSPACE_DIR /$PROJECT_FOLDER "
303+ cd " $WORKSPACE_DIR /$PROJECT_FOLDER " || return 1
305304 return 0
306305}
307306
@@ -352,7 +351,7 @@ setup_web_nodejs() {
352351 show_spinner " $cmd_pid "
353352 wait " $cmd_pid "
354353
355- cd " $WORKSPACE_DIR /$PROJECT_FOLDER "
354+ cd " $WORKSPACE_DIR /$PROJECT_FOLDER " || return 1
356355 return 0
357356}
358357
@@ -397,7 +396,7 @@ setup_app_nodejs() {
397396 # === 8️⃣ Run Tests ===
398397 log_msg_to " 🚀 Running 'npm run test'. This could take a few minutes. Follow the Automaton build here: https://automation.browserstack.com/"
399398 print_tests_running_log_section " npm run test"
400- npm run test >> $NOW_RUN_LOG_FILE 2>&1 || return 1 &
399+ npm run test >> " $NOW_RUN_LOG_FILE " 2>&1 || return 1 &
401400 cmd_pid=$! || return 1
402401
403402 show_spinner " $cmd_pid "
@@ -406,7 +405,7 @@ setup_app_nodejs() {
406405 # === 9️⃣ Wrap Up ===
407406 log_msg_to " ✅ Mobile JS setup and test execution completed successfully."
408407
409- cd " $WORKSPACE_DIR /$PROJECT_FOLDER "
408+ cd " $WORKSPACE_DIR /$PROJECT_FOLDER " || return 1
410409 return 0
411410}
412411
@@ -415,10 +414,10 @@ clone_repository() {
415414 install_folder=$2
416415 test_folder=$3
417416
418- rm -rf $install_folder
417+ rm -rf " $install_folder "
419418 log_msg_to " 📦 Cloning repo $repo_git into $install_folder "
420419 log_info " Cloning repository: $repo_git "
421- git clone https://github.com/BrowserStackCE/$repo_git .git " $install_folder " >> $NOW_RUN_LOG_FILE 2>&1 || return 1
420+ git clone https://github.com/BrowserStackCE/$repo_git .git " $install_folder " >> " $NOW_RUN_LOG_FILE " 2>&1 || return 1
422421 log_msg_to " ✅ Cloned repository: $repo_git into $install_folder "
423422 cd " $install_folder /$test_folder " || return 1
424423}
@@ -432,36 +431,17 @@ run_setup_wrapper() {
432431 case " $test_type " in
433432 Web)
434433 if [ " $WEB_PLAN_FETCHED " == true ]; then
435- run_setup $test_type $tech_stack
434+ run_setup " $test_type " " $tech_stack "
436435 else
437436 log_msg_to " ⚠️ Skipping Web setup — Web plan not fetched"
438437 fi
439438 ;;
440439 App)
441440 if [ " $MOBILE_PLAN_FETCHED " == true ]; then
442- run_setup $test_type $tech_stack
443- else
444- log_msg_to " ⚠️ Skipping Mobile setup — Mobile plan not fetched"
445- fi
446- ;;
447- Both)
448- local ran_any=false
449- if [ " $WEB_PLAN_FETCHED " == true ]; then
450- run_setup $test_type $tech_stack
451- ran_any=true
452- else
453- log_msg_to " ⚠️ Skipping Web setup — Web plan not fetched"
454- fi
455- if [ " $MOBILE_PLAN_FETCHED " == true ]; then
456- run_setup $test_type $tech_stack
457- ran_any=true
441+ run_setup " $test_type " " $tech_stack "
458442 else
459443 log_msg_to " ⚠️ Skipping Mobile setup — Mobile plan not fetched"
460444 fi
461- if [ " $ran_any " == false ]; then
462- log_msg_to " ❌ Both Web and Mobile setup were skipped. Exiting."
463- exit 1
464- fi
465445 ;;
466446 * )
467447 log_msg_to " ❌ Invalid TEST_TYPE: $TEST_TYPE "
@@ -531,6 +511,7 @@ detect_setup_python_env() {
531511 exit 1
532512 }
533513
514+ # shellcheck source=/dev/null
534515 source .venv/bin/activate
535516 log_success " Virtual environment created and activated."
536517}
0 commit comments