-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-github-actions.sh
More file actions
170 lines (142 loc) · 5.02 KB
/
test-github-actions.sh
File metadata and controls
170 lines (142 loc) · 5.02 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
#!/bin/bash
# GitHub Actions Simulation Script
# This script simulates the GitHub Actions environment for testing
echo "🧪 GitHub Actions AI Testing Simulation"
echo "========================================"
# Check if we're on Ubuntu-like system
if ! command -v apt-get &> /dev/null; then
echo "❌ This script is designed for Ubuntu/Debian systems (like GitHub Actions)"
echo " For Windows, use the PowerShell scripts instead"
exit 1
fi
# Set up environment variables
export GITHUB_ACTIONS=true
export RUNNER_OS=Linux
export OLLAMA_HOST=http://localhost:11434
echo "🔧 Step 1: Installing dependencies..."
# Install Java 11 (if not present)
if ! command -v java &> /dev/null; then
echo " Installing OpenJDK 11..."
sudo apt-get update
sudo apt-get install -y openjdk-11-jdk
fi
# Install Chrome (if not present)
if ! command -v google-chrome &> /dev/null; then
echo " Installing Chrome..."
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
sudo apt-get update
sudo apt-get install -y google-chrome-stable
fi
# Install ChromeDriver
echo " Setting up ChromeDriver..."
CHROME_VERSION=$(google-chrome --version | cut -d ' ' -f3 | cut -d '.' -f1-3)
echo " Chrome version: $CHROME_VERSION"
CHROMEDRIVER_VERSION=$(curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_VERSION}" 2>/dev/null || echo "114.0.5735.90")
echo " ChromeDriver version: $CHROMEDRIVER_VERSION"
if ! wget -O chromedriver.zip "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" 2>/dev/null; then
echo " Fallback: using package manager for ChromeDriver"
sudo apt-get install -y chromium-chromedriver
sudo ln -sf /usr/lib/chromium-browser/chromedriver /usr/local/bin/chromedriver
else
unzip -q chromedriver.zip
sudo mv chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver
rm chromedriver.zip
fi
echo "🤖 Step 2: Installing Ollama..."
# Install Ollama
if ! command -v ollama &> /dev/null; then
curl -fsSL https://ollama.ai/install.sh | sh
fi
# Start Ollama service
echo " Starting Ollama service..."
nohup ollama serve > ollama.log 2>&1 &
OLLAMA_PID=$!
echo " Ollama PID: $OLLAMA_PID"
# Wait for Ollama to be ready
echo " Waiting for Ollama to be ready..."
for i in {1..30}; do
if curl -f http://localhost:11434/api/tags >/dev/null 2>&1; then
echo " ✅ Ollama is ready!"
break
fi
echo " ⏳ Waiting for Ollama... ($i/30)"
sleep 2
done
# Verify Ollama is running
if ! curl -f http://localhost:11434/api/tags >/dev/null 2>&1; then
echo " ❌ Ollama failed to start"
cat ollama.log
exit 1
fi
echo "📦 Step 3: Pulling AI model..."
# Pull tinyllama model
echo " 📥 Pulling tinyllama model..."
if timeout 300 ollama pull tinyllama; then
echo " ✅ tinyllama model ready"
else
echo " ⚠️ Trying phi3-mini as fallback..."
if timeout 300 ollama pull phi3-mini; then
echo " ✅ phi3-mini model ready"
export AI_MODEL=phi3-mini
else
echo " ❌ Model pull failed"
ollama list
exit 1
fi
fi
echo "📋 Available models:"
ollama list
echo "🧪 Step 4: Setting up test environment..."
# Create test resources directory
mkdir -p src/test/resources
# Create AI test configuration
cat > src/test/resources/ai-test.properties << EOF
ai.model=${AI_MODEL:-tinyllama}
ai.timeout=120000
ai.enabled=true
ollama.host=http://localhost:11434
EOF
echo "📁 Created AI test configuration:"
cat src/test/resources/ai-test.properties
echo "🚀 Step 5: Running tests..."
# Verify environment
echo "🔍 Pre-test verification:"
echo " Java: $(java -version 2>&1 | head -n1)"
echo " Chrome: $(google-chrome --version)"
echo " ChromeDriver: $(chromedriver --version)"
echo " Ollama: $(curl -f http://localhost:11434/api/tags >/dev/null 2>&1 && echo 'Running' || echo 'Stopped')"
# Run AI tests
echo " Running AI fallback tests (SimpleAIDemo)..."
if mvn test -Dtest="SimpleAIDemo" \
-Dwebdriver.chrome.driver=/usr/local/bin/chromedriver \
-Dheadless=true \
-Djava.awt.headless=true; then
echo " ✅ AI fallback tests passed"
else
echo " ❌ AI fallback tests failed"
exit 1
fi
echo " Running full AI tests with Ollama..."
if mvn test -Dtest="QuickAITest" \
-Dwebdriver.chrome.driver=/usr/local/bin/chromedriver \
-Dheadless=true \
-Dai.model=${AI_MODEL:-tinyllama} \
-Dollama.host=http://localhost:11434 \
-Djava.awt.headless=true; then
echo " ✅ Full AI tests passed"
else
echo " ❌ Full AI tests failed"
exit 1
fi
echo "🎉 GitHub Actions simulation completed successfully!"
echo ""
echo "📊 Summary:"
echo " ✅ Environment setup complete"
echo " ✅ Ollama + ${AI_MODEL:-tinyllama} model working"
echo " ✅ AI tests passing"
echo " ✅ Ready for GitHub Actions deployment"
# Cleanup
kill $OLLAMA_PID 2>/dev/null
rm -f ollama.log nohup.out