From 63e0f6b78a572a21d8ed2941b525850d1d9c96e9 Mon Sep 17 00:00:00 2001 From: Yunxuan Shi Date: Fri, 20 Mar 2026 16:18:25 -0700 Subject: [PATCH 1/2] Add PR test workflow for MongoDB and DocumentDB Add GitHub Actions workflow that runs pytest against MongoDB and DocumentDB on pull requests. Includes test summary reporting and result analyzer integration. - .github/workflows/pr-tests.yml: CI workflow for PR checks - result_analyzer/__main__.py: python -m support for analyzer Signed-off-by: Yunxuan Shi # Conflicts: # documentdb_tests/compatibility/result_analyzer/__main__.py --- .github/workflows/pr-tests.yml | 143 ++++++++++++++++++ .../compatibility/result_analyzer/__main__.py | 4 + 2 files changed, 147 insertions(+) create mode 100644 .github/workflows/pr-tests.yml create mode 100644 documentdb_tests/compatibility/result_analyzer/__main__.py diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-tests.yml new file mode 100644 index 0000000..70da7c4 --- /dev/null +++ b/.github/workflows/pr-tests.yml @@ -0,0 +1,143 @@ +name: PR Tests + +on: + pull_request: + branches: [main] + +jobs: + test-mongodb: + name: Tests (MongoDB) + runs-on: ubuntu-latest + + services: + mongodb: + image: mongo:8.2 + ports: + - 27017:27017 + options: >- + --health-cmd "mongosh --eval 'db.runCommand({ ping: 1 })'" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-python@v6 + with: + python-version: "3.12" + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Create results directory + run: mkdir -p .test-results + + - name: Run tests against MongoDB + run: | + pytest documentdb_tests/ \ + --connection-string "mongodb://localhost:27017" \ + --engine-name mongodb \ + -n auto \ + -v \ + --json-report --json-report-file=.test-results/mongodb-report.json \ + --junitxml=.test-results/mongodb-results.xml + + - name: Generate test summary + if: always() + run: | + if [ -f .test-results/mongodb-report.json ]; then + python -m documentdb_tests.compatibility.result_analyzer -i .test-results/mongodb-report.json -o .test-results/mongodb-analysis.txt -f text || true + echo "## MongoDB Test Results" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + cat .test-results/mongodb-analysis.txt >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + fi + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v7 + with: + name: test-results-mongodb + path: .test-results/ + if-no-files-found: warn + + test-documentdb: + name: Tests (DocumentDB) + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - uses: actions/setup-python@v6 + with: + python-version: "3.12" + + - name: Install dependencies + run: pip install -r requirements.txt + + - name: Start DocumentDB + run: | + docker pull ghcr.io/documentdb/documentdb/documentdb-local:latest + docker run -dt -p 10260:10260 \ + --name documentdb \ + ghcr.io/documentdb/documentdb/documentdb-local:latest \ + --username testuser --password testpass + + - name: Wait for DocumentDB to be ready + run: | + echo "Waiting for DocumentDB..." + for i in $(seq 1 40); do + if python3 -c " + import pymongo + client = pymongo.MongoClient( + 'mongodb://testuser:testpass@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true', + serverSelectionTimeoutMS=3000 + ) + client.admin.command('ping') + print('DocumentDB is ready!') + " 2>/dev/null; then + exit 0 + fi + echo " Attempt $i/40 - waiting 5s..." + sleep 5 + done + echo "DocumentDB failed to start" + docker logs documentdb + exit 1 + + - name: Create results directory + run: mkdir -p .test-results + + - name: Run tests against DocumentDB + run: | + pytest documentdb_tests/ \ + --connection-string "mongodb://testuser:testpass@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true" \ + --engine-name documentdb \ + -n auto \ + -v \ + --json-report --json-report-file=.test-results/documentdb-report.json \ + --junitxml=.test-results/documentdb-results.xml + + - name: Generate test summary + if: always() + run: | + if [ -f .test-results/documentdb-report.json ]; then + python -m documentdb_tests.compatibility.result_analyzer -i .test-results/documentdb-report.json -o .test-results/documentdb-analysis.txt -f text || true + echo "## DocumentDB Test Results" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + cat .test-results/documentdb-analysis.txt >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + fi + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v7 + with: + name: test-results-documentdb + path: .test-results/ + if-no-files-found: warn + + - name: Stop DocumentDB + if: always() + run: docker stop documentdb && docker rm documentdb diff --git a/documentdb_tests/compatibility/result_analyzer/__main__.py b/documentdb_tests/compatibility/result_analyzer/__main__.py new file mode 100644 index 0000000..d9845b4 --- /dev/null +++ b/documentdb_tests/compatibility/result_analyzer/__main__.py @@ -0,0 +1,4 @@ +from documentdb_tests.compatibility.result_analyzer.cli import main +import sys + +sys.exit(main()) From 1cbf5401cc7ea6dc640cdcda4bd9ca763e4b9382 Mon Sep 17 00:00:00 2001 From: Yunxuan Shi Date: Tue, 24 Mar 2026 18:21:20 -0700 Subject: [PATCH 2/2] Fix artifact upload and simplify PR workflow - Use absolute paths (${{ github.workspace }}) for test output files - Add include-hidden-files: true for .test-results/ upload - Move upload step before generate summary step - Remove DocumentDB job (start with MongoDB only) - Remove unnecessary mkdir step Signed-off-by: Yunxuan Shi --- .github/workflows/pr-tests.yml | 98 +++------------------------------- 1 file changed, 8 insertions(+), 90 deletions(-) diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/pr-tests.yml index 70da7c4..3c12df2 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/pr-tests.yml @@ -30,9 +30,6 @@ jobs: - name: Install dependencies run: pip install -r requirements.txt - - name: Create results directory - run: mkdir -p .test-results - - name: Run tests against MongoDB run: | pytest documentdb_tests/ \ @@ -40,104 +37,25 @@ jobs: --engine-name mongodb \ -n auto \ -v \ - --json-report --json-report-file=.test-results/mongodb-report.json \ - --junitxml=.test-results/mongodb-results.xml - - - name: Generate test summary - if: always() - run: | - if [ -f .test-results/mongodb-report.json ]; then - python -m documentdb_tests.compatibility.result_analyzer -i .test-results/mongodb-report.json -o .test-results/mongodb-analysis.txt -f text || true - echo "## MongoDB Test Results" >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - cat .test-results/mongodb-analysis.txt >> $GITHUB_STEP_SUMMARY - echo '```' >> $GITHUB_STEP_SUMMARY - fi + --json-report --json-report-file=${{ github.workspace }}/.test-results/mongodb-report.json \ + --junitxml=${{ github.workspace }}/.test-results/mongodb-results.xml - name: Upload test results if: always() uses: actions/upload-artifact@v7 with: name: test-results-mongodb - path: .test-results/ + include-hidden-files: true + path: ${{ github.workspace }}/.test-results/ if-no-files-found: warn - test-documentdb: - name: Tests (DocumentDB) - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v6 - - - uses: actions/setup-python@v6 - with: - python-version: "3.12" - - - name: Install dependencies - run: pip install -r requirements.txt - - - name: Start DocumentDB - run: | - docker pull ghcr.io/documentdb/documentdb/documentdb-local:latest - docker run -dt -p 10260:10260 \ - --name documentdb \ - ghcr.io/documentdb/documentdb/documentdb-local:latest \ - --username testuser --password testpass - - - name: Wait for DocumentDB to be ready - run: | - echo "Waiting for DocumentDB..." - for i in $(seq 1 40); do - if python3 -c " - import pymongo - client = pymongo.MongoClient( - 'mongodb://testuser:testpass@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true', - serverSelectionTimeoutMS=3000 - ) - client.admin.command('ping') - print('DocumentDB is ready!') - " 2>/dev/null; then - exit 0 - fi - echo " Attempt $i/40 - waiting 5s..." - sleep 5 - done - echo "DocumentDB failed to start" - docker logs documentdb - exit 1 - - - name: Create results directory - run: mkdir -p .test-results - - - name: Run tests against DocumentDB - run: | - pytest documentdb_tests/ \ - --connection-string "mongodb://testuser:testpass@localhost:10260/?tls=true&tlsAllowInvalidCertificates=true" \ - --engine-name documentdb \ - -n auto \ - -v \ - --json-report --json-report-file=.test-results/documentdb-report.json \ - --junitxml=.test-results/documentdb-results.xml - - name: Generate test summary if: always() run: | - if [ -f .test-results/documentdb-report.json ]; then - python -m documentdb_tests.compatibility.result_analyzer -i .test-results/documentdb-report.json -o .test-results/documentdb-analysis.txt -f text || true - echo "## DocumentDB Test Results" >> $GITHUB_STEP_SUMMARY + if [ -f ${{ github.workspace }}/.test-results/mongodb-report.json ]; then + python -m documentdb_tests.compatibility.result_analyzer -i ${{ github.workspace }}/.test-results/mongodb-report.json -o ${{ github.workspace }}/.test-results/mongodb-analysis.txt -f text || true + echo "## MongoDB Test Results" >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY - cat .test-results/documentdb-analysis.txt >> $GITHUB_STEP_SUMMARY + cat ${{ github.workspace }}/.test-results/mongodb-analysis.txt >> $GITHUB_STEP_SUMMARY echo '```' >> $GITHUB_STEP_SUMMARY fi - - - name: Upload test results - if: always() - uses: actions/upload-artifact@v7 - with: - name: test-results-documentdb - path: .test-results/ - if-no-files-found: warn - - - name: Stop DocumentDB - if: always() - run: docker stop documentdb && docker rm documentdb