|
| 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 | + env: |
| 65 | + # Increase JVM heap for large CSV imports (example 04) |
| 66 | + ARCADEDB_JVM_MAX_HEAP: "8g" |
| 67 | + run: | |
| 68 | + cd bindings/python/examples |
| 69 | +
|
| 70 | + echo "🚀 Running Python Examples..." |
| 71 | + echo "" |
| 72 | +
|
| 73 | + # Initialize counters |
| 74 | + total=0 |
| 75 | + passed=0 |
| 76 | + failed=0 |
| 77 | + skipped=0 |
| 78 | +
|
| 79 | + # Create results file |
| 80 | + results_file="example-results.txt" |
| 81 | + > $results_file |
| 82 | +
|
| 83 | + # Find all Python example files (exclude download_sample_data.py as it's a utility) |
| 84 | + examples=$(ls [0-9]*.py 2>/dev/null | sort) |
| 85 | +
|
| 86 | + if [ -z "$examples" ]; then |
| 87 | + echo "❌ No example files found!" |
| 88 | + exit 1 |
| 89 | + fi |
| 90 | +
|
| 91 | + # Run each example |
| 92 | + for example in $examples; do |
| 93 | + total=$((total + 1)) |
| 94 | + echo "----------------------------------------" |
| 95 | + echo "📝 Running: $example" |
| 96 | + echo "----------------------------------------" |
| 97 | +
|
| 98 | + # Create a timeout wrapper to prevent hanging |
| 99 | + if timeout 1800 python "$example" > "${example}.log" 2>&1; then |
| 100 | + echo "✅ PASSED: $example" | tee -a $results_file |
| 101 | + passed=$((passed + 1)) |
| 102 | + else |
| 103 | + exit_code=$? |
| 104 | + if [ $exit_code -eq 124 ]; then |
| 105 | + echo "⏱️ TIMEOUT: $example (exceeded 30 minutes)" | tee -a $results_file |
| 106 | + failed=$((failed + 1)) |
| 107 | + else |
| 108 | + echo "❌ FAILED: $example (exit code: $exit_code)" | tee -a $results_file |
| 109 | + failed=$((failed + 1)) |
| 110 | + fi |
| 111 | + # Show last 20 lines of error log |
| 112 | + echo "Last 20 lines of output:" |
| 113 | + tail -n 20 "${example}.log" |
| 114 | + fi |
| 115 | + echo "" |
| 116 | + done |
| 117 | +
|
| 118 | + # Print summary |
| 119 | + echo "========================================" |
| 120 | + echo "📊 EXAMPLE TEST SUMMARY" |
| 121 | + echo "========================================" |
| 122 | + echo "Total: $total" |
| 123 | + echo "Passed: $passed ✅" |
| 124 | + echo "Failed: $failed ❌" |
| 125 | + echo "Skipped: $skipped ⏭️" |
| 126 | + echo "========================================" |
| 127 | + echo "" |
| 128 | +
|
| 129 | + # Output to GitHub Actions |
| 130 | + echo "total=$total" >> $GITHUB_OUTPUT |
| 131 | + echo "passed=$passed" >> $GITHUB_OUTPUT |
| 132 | + echo "failed=$failed" >> $GITHUB_OUTPUT |
| 133 | + echo "skipped=$skipped" >> $GITHUB_OUTPUT |
| 134 | +
|
| 135 | + # Show detailed results |
| 136 | + echo "Detailed Results:" |
| 137 | + cat $results_file |
| 138 | +
|
| 139 | + # Exit with error if any failed |
| 140 | + if [ $failed -gt 0 ]; then |
| 141 | + echo "❌ Some examples failed!" |
| 142 | + exit 1 |
| 143 | + else |
| 144 | + echo "✅ All examples passed!" |
| 145 | + fi |
| 146 | +
|
| 147 | + - name: Generate test summary |
| 148 | + if: always() |
| 149 | + run: | |
| 150 | + cd bindings/python/examples |
| 151 | +
|
| 152 | + echo "## 🎮 Python Examples Test Results" >> $GITHUB_STEP_SUMMARY |
| 153 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 154 | +
|
| 155 | + total="${{ steps.run_examples.outputs.total || '0' }}" |
| 156 | + passed="${{ steps.run_examples.outputs.passed || '0' }}" |
| 157 | + failed="${{ steps.run_examples.outputs.failed || '0' }}" |
| 158 | +
|
| 159 | + if [ "${{ steps.run_examples.outcome }}" = "success" ]; then |
| 160 | + echo "✅ **Status**: ALL EXAMPLES PASSED ($passed/$total)" >> $GITHUB_STEP_SUMMARY |
| 161 | + else |
| 162 | + echo "❌ **Status**: SOME EXAMPLES FAILED ($passed/$total passed)" >> $GITHUB_STEP_SUMMARY |
| 163 | + fi |
| 164 | +
|
| 165 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 166 | + echo "### Summary" >> $GITHUB_STEP_SUMMARY |
| 167 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 168 | + echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY |
| 169 | + echo "|--------|------:|" >> $GITHUB_STEP_SUMMARY |
| 170 | + echo "| 📝 Total | $total |" >> $GITHUB_STEP_SUMMARY |
| 171 | + echo "| ✅ Passed | $passed |" >> $GITHUB_STEP_SUMMARY |
| 172 | + echo "| ❌ Failed | $failed |" >> $GITHUB_STEP_SUMMARY |
| 173 | + echo "| ⏭️ Skipped | ${{ steps.run_examples.outputs.skipped || '0' }} |" >> $GITHUB_STEP_SUMMARY |
| 174 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 175 | +
|
| 176 | + # Add detailed results if available |
| 177 | + if [ -f example-results.txt ]; then |
| 178 | + echo "### Detailed Results" >> $GITHUB_STEP_SUMMARY |
| 179 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 180 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 181 | + cat example-results.txt >> $GITHUB_STEP_SUMMARY |
| 182 | + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |
| 183 | + fi |
| 184 | +
|
| 185 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 186 | + echo "### Examples Tested" >> $GITHUB_STEP_SUMMARY |
| 187 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 188 | + echo "- 01_simple_document_store.py - Document CRUD operations" >> $GITHUB_STEP_SUMMARY |
| 189 | + echo "- 02_social_network_graph.py - Graph modeling and traversal" >> $GITHUB_STEP_SUMMARY |
| 190 | + echo "- 03_vector_search.py - Vector embeddings and similarity search" >> $GITHUB_STEP_SUMMARY |
| 191 | + echo "- 04_csv_import_documents.py - CSV data import with type inference" >> $GITHUB_STEP_SUMMARY |
| 192 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 193 | + echo "_Note: Example 04 requires the MovieLens dataset. If it fails, the dataset may need to be downloaded._" >> $GITHUB_STEP_SUMMARY |
| 194 | +
|
| 195 | + - name: Upload example logs |
| 196 | + if: always() |
| 197 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 198 | + with: |
| 199 | + name: example-logs |
| 200 | + path: | |
| 201 | + bindings/python/examples/*.log |
| 202 | + bindings/python/examples/example-results.txt |
| 203 | + retention-days: 7 |
| 204 | + |
| 205 | + - name: Upload example databases |
| 206 | + if: failure() |
| 207 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 208 | + with: |
| 209 | + name: example-databases |
| 210 | + path: bindings/python/examples/my_test_databases/ |
| 211 | + retention-days: 3 |
0 commit comments