Skip to content

Commit 377370a

Browse files
committed
Add GitHub Actions workflow to test Python examples
1 parent ac22e69 commit 377370a

1 file changed

Lines changed: 208 additions & 0 deletions

File tree

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
name: Test Python Examples
2+
3+
on:
4+
# Run on any push to any branch
5+
push:
6+
7+
# Run on any pull request
8+
pull_request:
9+
10+
# Allow being called by other workflows (e.g., release workflow)
11+
workflow_call:
12+
13+
# Allow manual trigger
14+
workflow_dispatch:
15+
16+
jobs:
17+
test-examples:
18+
name: Test Python Examples
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
27+
28+
- name: Build minimal distribution
29+
run: |
30+
cd bindings/python
31+
echo "🔨 Building minimal distribution for examples..."
32+
./build-all.sh minimal
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
36+
with:
37+
python-version: '3.11'
38+
39+
- name: Install Java (required for JPype)
40+
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
41+
with:
42+
distribution: 'temurin'
43+
java-version: '21'
44+
45+
- name: Install ArcadeDB Python bindings
46+
run: |
47+
cd bindings/python
48+
pip install dist/*minimal*.whl
49+
50+
- name: Install example dependencies
51+
run: |
52+
# Install dependencies needed by examples
53+
pip install numpy requests
54+
55+
- name: Download sample data
56+
run: |
57+
cd bindings/python/examples
58+
echo "📥 Downloading sample data for examples..."
59+
# Download large dataset for comprehensive testing
60+
python download_sample_data.py
61+
62+
- name: Run all examples
63+
id: run_examples
64+
run: |
65+
cd bindings/python/examples
66+
67+
echo "🚀 Running Python Examples..."
68+
echo ""
69+
70+
# Initialize counters
71+
total=0
72+
passed=0
73+
failed=0
74+
skipped=0
75+
76+
# Create results file
77+
results_file="example-results.txt"
78+
> $results_file
79+
80+
# Find all Python example files (exclude download_sample_data.py as it's a utility)
81+
examples=$(ls [0-9]*.py 2>/dev/null | sort)
82+
83+
if [ -z "$examples" ]; then
84+
echo "❌ No example files found!"
85+
exit 1
86+
fi
87+
88+
# Run each example
89+
for example in $examples; do
90+
total=$((total + 1))
91+
echo "----------------------------------------"
92+
echo "📝 Running: $example"
93+
echo "----------------------------------------"
94+
95+
# Create a timeout wrapper to prevent hanging
96+
if timeout 300 python "$example" > "${example}.log" 2>&1; then
97+
echo "✅ PASSED: $example" | tee -a $results_file
98+
passed=$((passed + 1))
99+
else
100+
exit_code=$?
101+
if [ $exit_code -eq 124 ]; then
102+
echo "⏱️ TIMEOUT: $example (exceeded 5 minutes)" | tee -a $results_file
103+
failed=$((failed + 1))
104+
else
105+
echo "❌ FAILED: $example (exit code: $exit_code)" | tee -a $results_file
106+
failed=$((failed + 1))
107+
fi
108+
# Show last 20 lines of error log
109+
echo "Last 20 lines of output:"
110+
tail -n 20 "${example}.log"
111+
fi
112+
echo ""
113+
done
114+
115+
# Print summary
116+
echo "========================================"
117+
echo "📊 EXAMPLE TEST SUMMARY"
118+
echo "========================================"
119+
echo "Total: $total"
120+
echo "Passed: $passed ✅"
121+
echo "Failed: $failed ❌"
122+
echo "Skipped: $skipped ⏭️"
123+
echo "========================================"
124+
echo ""
125+
126+
# Output to GitHub Actions
127+
echo "total=$total" >> $GITHUB_OUTPUT
128+
echo "passed=$passed" >> $GITHUB_OUTPUT
129+
echo "failed=$failed" >> $GITHUB_OUTPUT
130+
echo "skipped=$skipped" >> $GITHUB_OUTPUT
131+
132+
# Show detailed results
133+
echo "Detailed Results:"
134+
cat $results_file
135+
136+
# Exit with error if any failed
137+
if [ $failed -gt 0 ]; then
138+
echo "❌ Some examples failed!"
139+
exit 1
140+
else
141+
echo "✅ All examples passed!"
142+
fi
143+
144+
- name: Generate test summary
145+
if: always()
146+
run: |
147+
cd bindings/python/examples
148+
149+
echo "## 🎮 Python Examples Test Results" >> $GITHUB_STEP_SUMMARY
150+
echo "" >> $GITHUB_STEP_SUMMARY
151+
152+
total="${{ steps.run_examples.outputs.total || '0' }}"
153+
passed="${{ steps.run_examples.outputs.passed || '0' }}"
154+
failed="${{ steps.run_examples.outputs.failed || '0' }}"
155+
156+
if [ "${{ steps.run_examples.outcome }}" = "success" ]; then
157+
echo "✅ **Status**: ALL EXAMPLES PASSED ($passed/$total)" >> $GITHUB_STEP_SUMMARY
158+
else
159+
echo "❌ **Status**: SOME EXAMPLES FAILED ($passed/$total passed)" >> $GITHUB_STEP_SUMMARY
160+
fi
161+
162+
echo "" >> $GITHUB_STEP_SUMMARY
163+
echo "### Summary" >> $GITHUB_STEP_SUMMARY
164+
echo "" >> $GITHUB_STEP_SUMMARY
165+
echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY
166+
echo "|--------|------:|" >> $GITHUB_STEP_SUMMARY
167+
echo "| 📝 Total | $total |" >> $GITHUB_STEP_SUMMARY
168+
echo "| ✅ Passed | $passed |" >> $GITHUB_STEP_SUMMARY
169+
echo "| ❌ Failed | $failed |" >> $GITHUB_STEP_SUMMARY
170+
echo "| ⏭️ Skipped | ${{ steps.run_examples.outputs.skipped || '0' }} |" >> $GITHUB_STEP_SUMMARY
171+
echo "" >> $GITHUB_STEP_SUMMARY
172+
173+
# Add detailed results if available
174+
if [ -f example-results.txt ]; then
175+
echo "### Detailed Results" >> $GITHUB_STEP_SUMMARY
176+
echo "" >> $GITHUB_STEP_SUMMARY
177+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
178+
cat example-results.txt >> $GITHUB_STEP_SUMMARY
179+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
180+
fi
181+
182+
echo "" >> $GITHUB_STEP_SUMMARY
183+
echo "### Examples Tested" >> $GITHUB_STEP_SUMMARY
184+
echo "" >> $GITHUB_STEP_SUMMARY
185+
echo "- 01_simple_document_store.py - Document CRUD operations" >> $GITHUB_STEP_SUMMARY
186+
echo "- 02_social_network_graph.py - Graph modeling and traversal" >> $GITHUB_STEP_SUMMARY
187+
echo "- 03_vector_search.py - Vector embeddings and similarity search" >> $GITHUB_STEP_SUMMARY
188+
echo "- 04_csv_import_documents.py - CSV data import with type inference" >> $GITHUB_STEP_SUMMARY
189+
echo "" >> $GITHUB_STEP_SUMMARY
190+
echo "_Note: Example 04 requires the MovieLens dataset. If it fails, the dataset may need to be downloaded._" >> $GITHUB_STEP_SUMMARY
191+
192+
- name: Upload example logs
193+
if: always()
194+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
195+
with:
196+
name: example-logs
197+
path: |
198+
bindings/python/examples/*.log
199+
bindings/python/examples/example-results.txt
200+
retention-days: 7
201+
202+
- name: Upload example databases
203+
if: failure()
204+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
205+
with:
206+
name: example-databases
207+
path: bindings/python/examples/my_test_databases/
208+
retention-days: 3

0 commit comments

Comments
 (0)