[TST] Add v2 API #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: V2 API PR Validation | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| paths: | |
| - 'src/main/java/tech/amikos/chromadb/v2/**' | |
| - 'src/test/java/tech/amikos/chromadb/v2/**' | |
| jobs: | |
| quick-validation: | |
| name: Quick V2 API Validation | |
| runs-on: ubuntu-latest | |
| services: | |
| chroma: | |
| image: chromadb/chroma:0.5.15 | |
| ports: | |
| - 8000:8000 | |
| env: | |
| ALLOW_RESET: 'TRUE' | |
| IS_PERSISTENT: 'FALSE' | |
| options: >- | |
| --health-cmd "curl -f http://localhost:8000/api/v1 || exit 1" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Java 11 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '11' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Check code changes | |
| id: changes | |
| run: | | |
| echo "Changed files in V2 API:" | |
| git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E "v2/|V2" || true | |
| # Check if only test files changed | |
| if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E "src/main/java.*v2" > /dev/null; then | |
| echo "src_changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "src_changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -E "src/test/java.*v2" > /dev/null; then | |
| echo "test_changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "test_changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Compile V2 API code | |
| run: | | |
| mvn compile -pl . -am | |
| - name: Run checkstyle on V2 API | |
| run: | | |
| mvn checkstyle:check -Dcheckstyle.includes="**/v2/**/*.java" || true | |
| - name: Run V2 API unit tests | |
| if: steps.changes.outputs.src_changed == 'true' || steps.changes.outputs.test_changed == 'true' | |
| run: | | |
| mvn test \ | |
| -Dtest="tech.amikos.chromadb.v2.**Test" \ | |
| -DfailIfNoTests=false | |
| env: | |
| CHROMA_URL: http://localhost:8000 | |
| - name: Check test coverage | |
| if: steps.changes.outputs.src_changed == 'true' | |
| run: | | |
| mvn jacoco:prepare-agent test jacoco:report \ | |
| -Dtest="tech.amikos.chromadb.v2.**Test" \ | |
| -DfailIfNoTests=false | |
| # Extract coverage percentage (simplified) | |
| if [ -f target/site/jacoco/index.html ]; then | |
| echo "Code coverage report generated" | |
| # You can add coverage threshold checks here | |
| fi | |
| - name: Run basic integration test | |
| run: | | |
| cat > BasicV2IntegrationTest.java << 'EOF' | |
| import tech.amikos.chromadb.v2.auth.AuthProvider; | |
| import tech.amikos.chromadb.v2.client.Collection; | |
| import tech.amikos.chromadb.v2.client.ServerClient; | |
| public class BasicV2IntegrationTest { | |
| public static void main(String[] args) throws Exception { | |
| ServerClient client = ServerClient.builder() | |
| .baseUrl("http://localhost:8000") | |
| .auth(AuthProvider.none()) | |
| .build(); | |
| try { | |
| // Test heartbeat | |
| String heartbeat = client.heartbeat(); | |
| System.out.println("✅ Heartbeat successful: " + heartbeat); | |
| // Test collection creation | |
| Collection collection = client.createCollection("pr_validation_test"); | |
| System.out.println("✅ Collection created: " + collection.getName()); | |
| // Test add operation | |
| collection.add() | |
| .ids(java.util.Arrays.asList("test1")) | |
| .embeddings(java.util.Arrays.asList( | |
| java.util.Arrays.asList(0.1f, 0.2f, 0.3f) | |
| )) | |
| .execute(); | |
| System.out.println("✅ Document added successfully"); | |
| // Test count | |
| int count = collection.count(); | |
| if (count == 1) { | |
| System.out.println("✅ Count verified: " + count); | |
| } else { | |
| throw new RuntimeException("Count mismatch: expected 1, got " + count); | |
| } | |
| // Cleanup | |
| client.deleteCollection("pr_validation_test"); | |
| System.out.println("✅ Collection deleted successfully"); | |
| System.out.println("\n✅ All basic V2 API operations passed!"); | |
| System.exit(0); | |
| } catch (Exception e) { | |
| System.err.println("❌ Test failed: " + e.getMessage()); | |
| e.printStackTrace(); | |
| System.exit(1); | |
| } | |
| } | |
| } | |
| EOF | |
| javac -cp "target/classes:target/test-classes:$(mvn dependency:build-classpath -Dmdep.outputFile=/dev/stdout -q)" BasicV2IntegrationTest.java | |
| java -cp ".:target/classes:target/test-classes:$(mvn dependency:build-classpath -Dmdep.outputFile=/dev/stdout -q)" BasicV2IntegrationTest | |
| - name: Comment PR with results | |
| if: always() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| let comment = '## V2 API PR Validation Results\n\n'; | |
| // Add emoji based on job status | |
| const status = '${{ job.status }}'; | |
| if (status === 'success') { | |
| comment += '✅ **All checks passed!**\n\n'; | |
| } else if (status === 'failure') { | |
| comment += '❌ **Some checks failed**\n\n'; | |
| } else { | |
| comment += '⚠️ **Validation canceled**\n\n'; | |
| } | |
| // Add change summary | |
| comment += '### Changes Detected\n'; | |
| comment += '- Source files changed: ${{ steps.changes.outputs.src_changed }}\n'; | |
| comment += '- Test files changed: ${{ steps.changes.outputs.test_changed }}\n\n'; | |
| // Add test results if available | |
| const testResults = `${{ steps.test-results.outputs.summary }}`; | |
| if (testResults) { | |
| comment += '### Test Results\n'; | |
| comment += testResults + '\n\n'; | |
| } | |
| comment += '---\n'; | |
| comment += `🔗 [View full workflow run](${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID})\n`; | |
| // Find existing comment | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| }); | |
| const botComment = comments.find(comment => | |
| comment.user.type === 'Bot' && | |
| comment.body.includes('V2 API PR Validation Results') | |
| ); | |
| if (botComment) { | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: botComment.id, | |
| body: comment | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: comment | |
| }); | |
| } | |
| code-quality: | |
| name: V2 API Code Quality | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Java 11 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '11' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Run SpotBugs on V2 API | |
| continue-on-error: true | |
| run: | | |
| mvn compile spotbugs:check -Dspotbugs.includeFilterFile=v2-api-include.xml || true | |
| - name: Run PMD on V2 API | |
| continue-on-error: true | |
| run: | | |
| mvn pmd:check -Dpmd.includes="**/v2/**/*.java" || true | |
| - name: Check for security issues | |
| continue-on-error: true | |
| run: | | |
| mvn dependency-check:check -DfailBuildOnCVSS=8 || true | |
| - name: Generate quality report | |
| if: always() | |
| run: | | |
| echo "## Code Quality Report" >> quality-report.md | |
| echo "" >> quality-report.md | |
| if [ -f target/spotbugsXml.xml ]; then | |
| echo "### SpotBugs" >> quality-report.md | |
| echo "Report generated at target/spotbugsXml.xml" >> quality-report.md | |
| fi | |
| if [ -f target/pmd.xml ]; then | |
| echo "### PMD" >> quality-report.md | |
| echo "Report generated at target/pmd.xml" >> quality-report.md | |
| fi | |
| cat quality-report.md >> $GITHUB_STEP_SUMMARY | |
| - name: Upload quality reports | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: quality-reports-v2 | |
| path: | | |
| target/spotbugsXml.xml | |
| target/pmd.xml | |
| target/dependency-check-report.html |