-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-environment.sh
More file actions
executable file
·263 lines (222 loc) · 7.53 KB
/
check-environment.sh
File metadata and controls
executable file
·263 lines (222 loc) · 7.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/env bash
# Yapster Training Environment Checker for Linux and macOS
# Verifies that all required tools are installed with correct versions
# and that Robot Framework with Browser library works properly
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Counters
CHECKS_PASSED=0
CHECKS_FAILED=0
# Parse command line arguments
CHECK_CORE=true
CHECK_ROBOT=true
if [ $# -gt 0 ]; then
CHECK_CORE=false
CHECK_ROBOT=false
for arg in "$@"; do
case $arg in
core|tools)
CHECK_CORE=true
;;
robot|rf)
CHECK_ROBOT=true
;;
all)
CHECK_CORE=true
CHECK_ROBOT=true
;;
*)
echo "Usage: $0 [core|tools] [robot|rf] [all]"
echo " core/tools: Check core development tools"
echo " robot/rf: Check Robot Framework environment"
echo " all: Check everything (default if no args)"
echo " (no args): Check everything"
exit 1
;;
esac
done
fi
echo -e "${BLUE}🚀 Yapster Training Environment Checker${NC}"
echo -e "${BLUE}=======================================${NC}"
echo ""
# Function to print status
print_status() {
if [ $1 -eq 0 ]; then
printf "%b\n" "${GREEN}✅ $2${NC}"
((CHECKS_PASSED++))
else
printf "%b\n" "${RED}❌ $2${NC}"
((CHECKS_FAILED++))
fi
}
# Function to compare versions
version_compare() {
local required=$1
local actual=$2
IFS='.' read -r -a required_parts <<< "$required"
IFS='.' read -r -a actual_parts <<< "$actual"
local length=${#required_parts[@]}
if [ ${#actual_parts[@]} -gt $length ]; then
length=${#actual_parts[@]}
fi
for ((i=0; i<length; i++)); do
local req_part=${required_parts[i]:-0}
local act_part=${actual_parts[i]:-0}
# Ensure numbers are compared properly even with leading zeros
req_part=$((10#${req_part}))
act_part=$((10#${act_part}))
if (( act_part > req_part )); then
return 0
elif (( act_part < req_part )); then
return 1
fi
done
return 0
}
extract_version() {
echo "$1" | awk 'match($0, /[0-9]+(\.[0-9]+)+/) { print substr($0, RSTART, RLENGTH); exit }'
}
# Function to check tool version
check_tool_version() {
local tool=$1
local required_version=$2
local version_command=$3
echo -n "Checking $tool... "
if ! command -v $tool &> /dev/null; then
print_status 1 "$tool is not installed"
return 1
fi
local actual_version
actual_version=$(eval $version_command 2>/dev/null | head -n1)
actual_version=$(extract_version "$actual_version")
if [ -z "$actual_version" ]; then
print_status 1 "$tool version could not be determined"
return 1
fi
if version_compare "$required_version" "$actual_version"; then
print_status 0 "$tool $actual_version (>= $required_version required)"
else
print_status 1 "$tool $actual_version (>= $required_version required)"
return 1
fi
}
# Load required versions from file
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSIONS_FILE="$SCRIPT_DIR/required-versions.txt"
if [ ! -f "$VERSIONS_FILE" ]; then
printf "%b\n" "${RED}❌ Required versions file not found: $VERSIONS_FILE${NC}"
exit 1
fi
printf "%b\n" "${YELLOW}Loading required versions from: $VERSIONS_FILE${NC}"
printf "\n"
# Parse versions file
while IFS='=' read -r tool version; do
# Skip comments and empty lines
[[ $tool =~ ^#.*$ ]] && continue
[[ -z $tool ]] && continue
tool=$(echo "$tool" | tr -d '[:space:]')
version=$(echo "$version" | tr -d '[:space:]')
# Only allow expected tool names to avoid surprises
case "$tool" in
node|npm|python|git|robot|browser)
eval "REQUIRED_${tool}=\"$version\""
;;
*)
;;
esac
done < "$VERSIONS_FILE"
if [ "$CHECK_CORE" = true ]; then
echo -e "${BLUE}📋 Checking Core Tools${NC}"
echo "====================="
check_tool_version "node" "$REQUIRED_node" "node --version"
# Check npm
check_tool_version "npm" "$REQUIRED_npm" "npm --version"
# Check Python
check_tool_version "python3" "$REQUIRED_python" "python3 --version"
# Check Git
check_tool_version "git" "$REQUIRED_git" "git --version"
echo ""
fi
if [ "$CHECK_ROBOT" = true ]; then
echo -e "${BLUE}🤖 Checking Robot Framework Environment${NC}"
echo "========================================"
# Check if Robot Framework venv exists
VENV_PATH="$SCRIPT_DIR/atests/.venv"
echo -n "Checking Robot Framework virtual environment... "
if [ -d "$VENV_PATH" ]; then
print_status 0 "Virtual environment found at atests/.venv"
else
print_status 1 "Virtual environment not found at atests/.venv"
fi
# Check Robot Framework installation in venv
echo -n "Checking Robot Framework installation... "
if [ -f "$VENV_PATH/bin/robot" ]; then
rf_version=$("$VENV_PATH/bin/python" -c "import robot; print(robot.__version__)" 2>/dev/null)
if [ -n "$rf_version" ]; then
if version_compare "$REQUIRED_robot" "$rf_version"; then
print_status 0 "Robot Framework $rf_version (>= $REQUIRED_robot required)"
else
print_status 1 "Robot Framework $rf_version (>= $REQUIRED_robot required)"
fi
else
print_status 1 "Robot Framework version could not be determined"
fi
else
print_status 1 "Robot Framework not found in virtual environment"
fi
# Check Browser library installation
echo -n "Checking Browser library... "
if "$VENV_PATH/bin/python" -c "import Browser" 2>/dev/null; then
browser_version=$("$VENV_PATH/bin/python" -c "import Browser; print(Browser.__version__)" 2>/dev/null)
if [ -n "$browser_version" ]; then
if version_compare "$REQUIRED_browser" "$browser_version"; then
print_status 0 "Browser library $browser_version (>= $REQUIRED_browser required)"
else
print_status 1 "Browser library $browser_version (>= $REQUIRED_browser required)"
fi
else
print_status 1 "Browser library version could not be determined"
fi
else
print_status 1 "Browser library not found"
fi
# Test Browser library functionality
echo -n "Testing Browser library functionality... "
if "$VENV_PATH/bin/python" -c "
from Browser import Browser
import sys
try:
browser = Browser()
print('Browser library test passed')
sys.exit(0)
except Exception as e:
print(f'Browser library test failed: {e}')
sys.exit(1)
" 2>/dev/null; then
print_status 0 "Browser library functionality test passed"
else
print_status 1 "Browser library functionality test failed"
fi
echo ""
fi
echo -e "${BLUE}📊 Summary${NC}"
echo "=========="
printf "%b\n" "${GREEN}Passed: $CHECKS_PASSED${NC}"
printf "%b\n" "${RED}Failed: $CHECKS_FAILED${NC}"
printf "\n"
if [ $CHECKS_FAILED -eq 0 ]; then
printf "%b\n" "${GREEN}🎉 Environment check completed successfully!${NC}"
printf "%b\n" "${GREEN}Your system is ready for Yapster training.${NC}"
exit 0
else
printf "%b\n" "${RED}⚠️ Environment check found issues.${NC}"
printf "%b\n" "${YELLOW}Please fix the failed checks before starting training.${NC}"
printf "%b\n" "${YELLOW}Run the setup script for your platform if needed:${NC}"
printf "%b\n" "${YELLOW} ./setup-linux.sh${NC}"
printf "%b\n" "${YELLOW} ./setup-macos.sh${NC}"
exit 1
fi