feat: Enhance CI workflow with improved test coverage and integration… #482
Workflow file for this run
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: Main | ||
|
Check failure on line 1 in .github/workflows/main.yaml
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| tags: | ||
| - "**" | ||
| paths-ignore: | ||
| - "docs/**" | ||
| - "README.rst" | ||
| - "LICENSE.md" | ||
| - "publishing.md" | ||
| pull_request: | ||
| env: | ||
| DOTNET_VERSION: "8.x" | ||
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | ||
| DOTNET_CLI_TELEMETRY_OPTOUT: true | ||
| OKTA_CLIENT_SECRET: ${{ secrets.OKTA_CLIENT_SECRET }} | ||
| OKTA_DUMMY_CI_PW: ${{ secrets.OKTA_DUMMY_CI_PW }} | ||
| WEAVIATE_VERSIONS: '["1.31.16", "1.32.11", "1.33.0", "1.34.0-rc.0"]' | ||
| jobs: | ||
| check_formatting: | ||
| name: Check Formatting | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
| - name: Get list of changed C# files | ||
| id: changed-files | ||
| uses: tj-actions/changed-files@v46 | ||
| with: | ||
| files: | | ||
| **.cs | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
| - name: Check formatting | ||
| if: steps.changed-files.outputs.any_changed == 'true' | ||
| run: | | ||
| dotnet tool restore | ||
| dotnet csharpier check ${{ steps.changed-files.outputs.all_changed_files }} | ||
| unit-tests: | ||
| name: Unit Tests | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
| - name: Cache NuGet packages | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.nuget/packages | ||
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.*proj') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-nuget- | ||
| - name: Restore dependencies | ||
| run: dotnet restore | ||
| - name: Run unit tests with coverage | ||
| run: | | ||
| dotnet test --no-restore \ | ||
| --filter "FullyQualifiedName~Weaviate.Client.Tests.Unit" \ | ||
| --logger "trx;LogFileName=test-unit-results.trx" \ | ||
| --collect:"XPlat Code Coverage" \ | ||
| --results-directory ./coverage | ||
| - name: Upload test results | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: test-results-unit | ||
| path: src/Weaviate.Client.Tests/TestResults/test-unit-results.trx | ||
| retention-days: 7 | ||
| - name: Upload coverage data | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: coverage-unit | ||
| path: ./coverage/**/coverage.cobertura.xml | ||
| retention-days: 7 | ||
| integration-quick: | ||
| name: Integration Tests (Quick) - Weaviate ${{ matrix.server }} | ||
| needs: [unit-tests] | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| server: ${{ fromJSON(env.WEAVIATE_VERSIONS) }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
| - name: Cache NuGet packages | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.nuget/packages | ||
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.*proj') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-nuget- | ||
| - name: Restore dependencies | ||
| run: dotnet restore | ||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| if: ${{ !github.event.pull_request.head.repo.fork && github.triggering_actor != 'dependabot[bot]' }} | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
| - name: Start Weaviate | ||
| run: /bin/bash ci/start_weaviate.sh ${{ matrix.server }} | ||
| - name: Run quick integration tests with coverage | ||
| run: | | ||
| dotnet test --no-restore \ | ||
| --filter "(Category!=Slow&Category!=RBAC&FullyQualifiedName~Integration)" \ | ||
| --logger "trx;LogFileName=test-integration-quick-${{ matrix.server }}.trx" \ | ||
| --collect:"XPlat Code Coverage" \ | ||
| --results-directory ./coverage | ||
| - name: Stop Weaviate | ||
| if: always() | ||
| run: /bin/bash ci/stop_weaviate.sh ${{ matrix.server }} | ||
| - name: Upload test results | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: test-results-integration-quick-${{ matrix.server }} | ||
| path: src/Weaviate.Client.Tests/TestResults/test-integration-quick-${{ matrix.server }}.trx | ||
| retention-days: 7 | ||
| - name: Upload coverage data | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: coverage-integration-quick-${{ matrix.server }} | ||
| path: ./coverage/**/coverage.cobertura.xml | ||
| retention-days: 7 | ||
| - name: Test Report | ||
| uses: dorny/test-reporter@v1 | ||
| if: always() | ||
| with: | ||
| name: Quick Integration Tests - Weaviate ${{ matrix.server }} | ||
| path: src/Weaviate.Client.Tests/TestResults/test-integration-quick-${{ matrix.server }}.trx | ||
| reporter: dotnet-trx | ||
| fail-on-error: false | ||
| integration-slow: | ||
| name: Integration Tests (Slow) - Weaviate ${{ matrix.server }} | ||
| needs: [integration-quick] | ||
| runs-on: ubuntu-latest | ||
| if: | | ||
| github.event_name == 'push' || | ||
| (github.event_name == 'pull_request' && | ||
| !github.event.pull_request.draft && | ||
| !contains(github.event.pull_request.body, '[skip-slow]')) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| server: ${{ fromJSON(env.WEAVIATE_VERSIONS) }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
| - name: Cache NuGet packages | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.nuget/packages | ||
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.*proj') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-nuget- | ||
| - name: Restore dependencies | ||
| run: dotnet restore | ||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| if: ${{ !github.event.pull_request.head.repo.fork && github.triggering_actor != 'dependabot[bot]' }} | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
| - name: Start Weaviate | ||
| run: /bin/bash ci/start_weaviate.sh ${{ matrix.server }} | ||
| - name: Run slow integration tests with coverage | ||
| run: | | ||
| dotnet test --no-restore \ | ||
| --filter "(Category=Slow&FullyQualifiedName~Integration)" \ | ||
| --logger "trx;LogFileName=test-integration-slow-${{ matrix.server }}.trx" \ | ||
| --collect:"XPlat Code Coverage" \ | ||
| --results-directory ./coverage | ||
| - name: Stop Weaviate | ||
| if: always() | ||
| run: /bin/bash ci/stop_weaviate.sh ${{ matrix.server }} | ||
| - name: Upload test results | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: test-results-integration-slow-${{ matrix.server }} | ||
| path: src/Weaviate.Client.Tests/TestResults/test-integration-slow-${{ matrix.server }}.trx | ||
| retention-days: 7 | ||
| - name: Upload coverage data | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: coverage-integration-slow-${{ matrix.server }} | ||
| path: ./coverage/**/coverage.cobertura.xml | ||
| retention-days: 7 | ||
| - name: Test Report | ||
| uses: dorny/test-reporter@v1 | ||
| if: always() | ||
| with: | ||
| name: Slow Integration Tests - Weaviate ${{ matrix.server }} | ||
| path: src/Weaviate.Client.Tests/TestResults/test-integration-slow-${{ matrix.server }}.trx | ||
| reporter: dotnet-trx | ||
| fail-on-error: false | ||
| integration-rbac: | ||
| name: Integration Tests (RBAC) - Weaviate ${{ matrix.server }} | ||
| needs: [integration-quick] | ||
| runs-on: ubuntu-latest | ||
| if: | | ||
| github.event_name == 'push' || | ||
| (github.event_name == 'pull_request' && | ||
| !github.event.pull_request.draft && | ||
| !contains(github.event.pull_request.body, '[skip-slow]')) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| server: ${{ fromJSON(env.WEAVIATE_VERSIONS) }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
| - name: Cache NuGet packages | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.nuget/packages | ||
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.*proj') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-nuget- | ||
| - name: Restore dependencies | ||
| run: dotnet restore | ||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| if: ${{ !github.event.pull_request.head.repo.fork && github.triggering_actor != 'dependabot[bot]' }} | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
| - name: Start Weaviate | ||
| run: /bin/bash ci/start_weaviate.sh ${{ matrix.server }} | ||
| - name: Run RBAC integration tests with coverage | ||
| run: | | ||
| dotnet test --no-restore \ | ||
| --filter "(Category=RBAC&FullyQualifiedName~Integration)" \ | ||
| --logger "trx;LogFileName=test-integration-rbac-${{ matrix.server }}.trx" \ | ||
| --collect:"XPlat Code Coverage" \ | ||
| --results-directory ./coverage | ||
| - name: Stop Weaviate | ||
| if: always() | ||
| run: /bin/bash ci/stop_weaviate.sh ${{ matrix.server }} | ||
| - name: Upload test results | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: test-results-integration-rbac-${{ matrix.server }} | ||
| path: src/Weaviate.Client.Tests/TestResults/test-integration-rbac-${{ matrix.server }}.trx | ||
| retention-days: 7 | ||
| - name: Upload coverage data | ||
| uses: actions/upload-artifact@v4 | ||
| if: always() | ||
| with: | ||
| name: coverage-integration-rbac-${{ matrix.server }} | ||
| path: ./coverage/**/coverage.cobertura.xml | ||
| retention-days: 7 | ||
| - name: Test Report | ||
| uses: dorny/test-reporter@v1 | ||
| if: always() | ||
| with: | ||
| name: RBAC Integration Tests - Weaviate ${{ matrix.server }} | ||
| path: src/Weaviate.Client.Tests/TestResults/test-integration-rbac-${{ matrix.server }}.trx | ||
| reporter: dotnet-trx | ||
| fail-on-error: false | ||
| test-summary: | ||
| name: Test Summary | ||
| needs: [unit-tests, integration-quick, integration-slow, integration-rbac] | ||
| runs-on: ubuntu-latest | ||
| if: always() | ||
| permissions: | ||
| pull-requests: write | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
| - name: Download all coverage artifacts | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: coverage-* | ||
| path: ./all-coverage | ||
| merge-multiple: true | ||
| - name: Install ReportGenerator | ||
| run: dotnet tool install -g dotnet-reportgenerator-globaltool | ||
| - name: Generate coverage report | ||
| run: | | ||
| reportgenerator \ | ||
| -reports:"./all-coverage/**/coverage.cobertura.xml" \ | ||
| -targetdir:"./coveragereport" \ | ||
| -reporttypes:"Html;MarkdownSummaryGithub;Cobertura" \ | ||
| -title:"Weaviate C# Client Coverage" | ||
| - name: Upload HTML coverage report | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: coverage-report-html | ||
| path: ./coveragereport | ||
| retention-days: 30 | ||
| - name: Add coverage to PR comment | ||
| uses: marocchino/sticky-pull-request-comment@v2 | ||
| if: github.event_name == 'pull_request' | ||
| with: | ||
| header: coverage | ||
| path: ./coveragereport/SummaryGithub.md | ||
| - name: Download all test results | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| pattern: test-results-* | ||
| path: ./all-test-results | ||
| - name: Generate test summary | ||
| run: | | ||
| dotnet tool update -g dotnet-trx | ||
| find ./all-test-results -name "*.trx" -exec trx {} \; | ||
| - name: Check test status | ||
| run: | | ||
| if [ "${{ needs.unit-tests.result }}" != "success" ]; then | ||
| echo "Unit tests failed" | ||
| exit 1 | ||
| fi | ||
| if [ "${{ needs.integration-quick.result }}" != "success" ]; then | ||
| echo "Quick integration tests failed" | ||
| exit 1 | ||
| fi | ||
| # Slow and RBAC tests are conditional - only fail if they ran and failed | ||
| if [ "${{ needs.integration-slow.result }}" == "failure" ]; then | ||
| echo "Slow integration tests failed" | ||
| exit 1 | ||
| fi | ||
| if [ "${{ needs.integration-rbac.result }}" == "failure" ]; then | ||
| echo "RBAC integration tests failed" | ||
| exit 1 | ||
| fi | ||
| build-and-publish: | ||
| name: Build and Publish to NuGet | ||
| needs: [test-summary] | ||
| runs-on: ubuntu-latest | ||
| if: startsWith(github.ref, 'refs/tags') | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Check for required secrets | ||
| run: | | ||
| if [ -z "${{ secrets.NUGET_APIKEY }}" ]; then echo "Warning: NUGET_APIKEY is not set"; fi | ||
| - name: Checkout code | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
| fetch-tags: true | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: ${{ env.DOTNET_VERSION }} | ||
| - name: Cache NuGet packages | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.nuget/packages | ||
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/.*proj') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-nuget- | ||
| - name: Create NuGet package | ||
| run: dotnet pack -c Release -o out src/Weaviate.Client/ | ||
| - name: Push package to NuGet | ||
| run: dotnet nuget push './out/*.nupkg' --skip-duplicate --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json | ||
| - name: GH Release | ||
| uses: softprops/action-gh-release@v1 | ||
| with: | ||
| generate_release_notes: true | ||
| draft: true | ||
| files: ./out/*.nupkg | ||