Feature/encryption custom compatibility testing #12
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: Encryption.Custom Compatibility Tests | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| - main | |
| paths: | |
| - 'Microsoft.Azure.Cosmos.Encryption.Custom/**' | |
| - '.github/workflows/encryption-custom-compatibility.yml' | |
| push: | |
| branches: | |
| - master | |
| - main | |
| paths: | |
| - 'Microsoft.Azure.Cosmos.Encryption.Custom/**' | |
| schedule: | |
| # Run daily at 2:00 AM UTC for comprehensive version matrix | |
| - cron: '0 2 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| test_versions: | |
| description: 'Comma-separated list of versions to test (e.g., "1.0.0-preview07,current"). Tests all pairs automatically.' | |
| required: false | |
| default: '1.0.0-preview07,current' | |
| type: string | |
| env: | |
| DOTNET_VERSION: '8.0.x' | |
| jobs: | |
| # Build current source code as NuGet package | |
| build-current-package: | |
| name: Build Current Package | |
| runs-on: ubuntu-latest | |
| outputs: | |
| package_version: ${{ steps.build-pkg.outputs.version }} | |
| package_path: ${{ steps.build-pkg.outputs.path }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Build and pack current version | |
| id: build-pkg | |
| run: | | |
| # Create artifacts/local-packages folder (required by Directory.Build.props RestoreSources) | |
| mkdir -p artifacts/local-packages | |
| # Generate unique version with PR/run number | |
| if [ "${{ github.event_name }}" == "pull_request" ]; then | |
| VERSION_SUFFIX="pr${{ github.event.pull_request.number }}-${{ github.run_number }}" | |
| else | |
| VERSION_SUFFIX="ci-${{ github.run_number }}" | |
| fi | |
| # Get base version from Directory.Build.props | |
| BASE_VERSION=$(grep -oPm1 "(?<=<CustomEncryptionVersion>)[^<]+" Directory.Build.props) | |
| PACKAGE_VERSION="${BASE_VERSION}-${VERSION_SUFFIX}" | |
| echo "Building package version: $PACKAGE_VERSION" | |
| echo "version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT | |
| # Build and pack | |
| dotnet pack Microsoft.Azure.Cosmos.Encryption.Custom/src/Microsoft.Azure.Cosmos.Encryption.Custom.csproj \ | |
| --configuration Release \ | |
| -p:Version=$PACKAGE_VERSION \ | |
| -p:PackageVersion=$PACKAGE_VERSION \ | |
| --output ./packages | |
| PACKAGE_FILE="./packages/Microsoft.Azure.Cosmos.Encryption.Custom.${PACKAGE_VERSION}.nupkg" | |
| echo "path=$PACKAGE_FILE" >> $GITHUB_OUTPUT | |
| echo "=========================================" | |
| echo "Built Package: $PACKAGE_FILE" | |
| ls -lh ./packages/ | |
| echo "=========================================" | |
| - name: Upload package artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: current-package | |
| path: ./packages/*.nupkg | |
| retention-days: 7 | |
| # Run compatibility tests | |
| compatibility-tests: | |
| name: Compatibility Tests | |
| needs: build-current-package | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Cache NuGet packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.nuget/packages | |
| key: ${{ runner.os }}-nuget-compat-${{ hashFiles('**/Directory.Packages.props', '**/packages.lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nuget-compat- | |
| ${{ runner.os }}-nuget- | |
| - name: Download current package | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: current-package | |
| path: ./local-packages | |
| - name: Setup test environment | |
| run: | | |
| # Create artifacts/local-packages folder (required by Directory.Build.props RestoreSources) | |
| mkdir -p artifacts/local-packages | |
| # Copy current package to artifacts/local-packages | |
| cp ./local-packages/*.nupkg artifacts/local-packages/ | |
| echo "Copied current package to artifacts/local-packages" | |
| ls -lh artifacts/local-packages/ | |
| - name: Update test configuration | |
| run: | | |
| CURRENT_VERSION="${{ needs.build-current-package.outputs.package_version }}" | |
| # Determine versions to test | |
| if [ -n "${{ github.event.inputs.test_versions }}" ]; then | |
| VERSIONS_INPUT="${{ github.event.inputs.test_versions }}" | |
| else | |
| VERSIONS_INPUT="1.0.0-preview07,current" | |
| fi | |
| # Replace "current" with actual version | |
| VERSIONS_INPUT=$(echo "$VERSIONS_INPUT" | sed "s/current/$CURRENT_VERSION/g") | |
| # Convert to JSON array | |
| IFS=',' read -ra VERSION_ARRAY <<< "$VERSIONS_INPUT" | |
| VERSIONS_JSON="[" | |
| for i in "${!VERSION_ARRAY[@]}"; do | |
| VERSION=$(echo "${VERSION_ARRAY[$i]}" | xargs) # trim whitespace | |
| if [ $i -gt 0 ]; then VERSIONS_JSON+=","; fi | |
| VERSIONS_JSON+="\"$VERSION\"" | |
| done | |
| VERSIONS_JSON+="]" | |
| echo "Test versions: $VERSIONS_JSON" | |
| # Update testconfig.json | |
| cd Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests | |
| # Update the versions array in testconfig.json | |
| jq ".versionMatrix.versions = $VERSIONS_JSON" testconfig.json > testconfig.json.tmp | |
| mv testconfig.json.tmp testconfig.json | |
| echo "Updated testconfig.json:" | |
| cat testconfig.json | |
| - name: Restore dependencies | |
| run: | | |
| dotnet restore Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests.csproj | |
| - name: Build compatibility tests | |
| run: | | |
| dotnet build Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests.csproj \ | |
| --configuration Release \ | |
| --no-restore | |
| - name: Run compatibility tests | |
| id: run-tests | |
| continue-on-error: true | |
| run: | | |
| dotnet test Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests.csproj \ | |
| --configuration Release \ | |
| --no-build \ | |
| --no-restore \ | |
| --logger "trx;LogFileName=compatibility-results.trx" \ | |
| --logger "console;verbosity=normal" \ | |
| --results-directory ./TestResults | |
| - name: Upload test results (TRX) | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results-trx | |
| path: ./TestResults/*.trx | |
| retention-days: 30 | |
| - name: Publish test results | |
| if: always() | |
| uses: dorny/test-reporter@v1 | |
| with: | |
| name: Compatibility Test Results | |
| path: './TestResults/*.trx' | |
| reporter: dotnet-trx | |
| fail-on-error: true | |
| fail-on-empty: true | |
| - name: Generate test summary | |
| if: always() | |
| run: | | |
| echo "## 🧪 Compatibility Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Package Version:** \`${{ needs.build-current-package.outputs.package_version }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ -f "./TestResults/compatibility-results.trx" ]; then | |
| # Parse TRX file for summary (basic parsing) | |
| TOTAL=$(grep -oP '(?<=total=")[^"]+' ./TestResults/compatibility-results.trx | head -1) | |
| PASSED=$(grep -oP '(?<=passed=")[^"]+' ./TestResults/compatibility-results.trx | head -1) | |
| FAILED=$(grep -oP '(?<=failed=")[^"]+' ./TestResults/compatibility-results.trx | head -1) | |
| echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY | |
| echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| Total Tests | $TOTAL |" >> $GITHUB_STEP_SUMMARY | |
| echo "| ✅ Passed | $PASSED |" >> $GITHUB_STEP_SUMMARY | |
| echo "| ❌ Failed | $FAILED |" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [ "$FAILED" == "0" ]; then | |
| echo "### ✅ All compatibility tests passed!" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "### ❌ Some compatibility tests failed" >> $GITHUB_STEP_SUMMARY | |
| echo "Check the detailed test report above for failure details." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| else | |
| echo "⚠️ Test results file not found" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "---" >> $GITHUB_STEP_SUMMARY | |
| echo "📦 **Tested Package:** \`Microsoft.Azure.Cosmos.Encryption.Custom.${{ needs.build-current-package.outputs.package_version }}.nupkg\`" >> $GITHUB_STEP_SUMMARY | |
| - name: Fail workflow if tests failed | |
| if: steps.run-tests.outcome == 'failure' | |
| run: | | |
| echo "❌ Compatibility tests failed" | |
| exit 1 | |
| - name: Display test summary | |
| if: always() | |
| run: | | |
| echo "=========================================" | |
| echo "Compatibility Test Summary" | |
| echo "=========================================" | |
| echo "Current Package Version: ${{ needs.build-current-package.outputs.package_version }}" | |
| echo "Test completed. Check test results artifact for details." | |
| echo "=========================================" | |
| if [ "${{ steps.run-tests.outcome }}" == "success" ]; then | |
| echo "✅ Full matrix compatibility test complete" | |
| else | |
| echo "❌ Compatibility test failures detected" | |
| fi | |
| echo "=========================================" |