Add Coverlet PR coverage reporting and cross-database boundary tests #363
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: .NET Pull Request | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| branches: [master, "codex/**"] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: live-databases-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| name: Test (${{ matrix.database }}) | |
| runs-on: ubuntu-22.04 | |
| timeout-minutes: 35 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| database: [Unit, SQLite, SQLServer, PostgreSQL, Oracle, MySQL, MariaDB, Firebird, Db2, Informix, Sybase, Hana] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 9.0.x | |
| - name: Start database | |
| shell: bash | |
| run: | | |
| mkdir -p TestResults | |
| bash .github/scripts/start-database.sh "${{ matrix.database }}" 2>&1 | tee TestResults/startup.log | |
| timeout-minutes: 15 | |
| - name: Build | |
| run: dotnet build Migrator.slnx -p:LiveDatabase=${{ matrix.database }} | |
| - name: Configure native IBM drivers | |
| if: matrix.database == 'Db2' || matrix.database == 'Informix' | |
| shell: bash | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libaio1 libxml2 unixodbc libncurses5 | |
| output="$GITHUB_WORKSPACE/src/Migrator.Tests/bin/Debug/net9.0" | |
| if [ "${{ matrix.database }}" = Db2 ]; then | |
| echo "DB2_CLI_DRIVER_INSTALL_PATH=$output/clidriver" >> "$GITHUB_ENV" | |
| echo "LD_LIBRARY_PATH=$output/clidriver/lib" >> "$GITHUB_ENV" | |
| else | |
| echo "DELIMIDENT=y" >> "$GITHUB_ENV" | |
| echo "INFORMIXDIR=$output/native" >> "$GITHUB_ENV" | |
| echo "LD_LIBRARY_PATH=$output/native/lib:$output/native/lib/cli:$output/native/lib/esql" >> "$GITHUB_ENV" | |
| fi | |
| - name: Test | |
| shell: pwsh | |
| run: ./.github/scripts/test.ps1 -Database ${{ matrix.database }} -Coverage | |
| - name: Verify coverage was collected | |
| run: python3 .github/scripts/normalize-code-coverage.py TestResults | |
| - name: Collect database logs | |
| if: always() | |
| run: | | |
| mkdir -p TestResults | |
| if docker inspect migrator-db >/dev/null 2>&1; then | |
| docker logs migrator-db > TestResults/database.log 2>&1 | |
| docker inspect migrator-db > TestResults/container.json | |
| fi | |
| - uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: test-results-${{ matrix.database }} | |
| overwrite: true | |
| path: TestResults/ | |
| if-no-files-found: error | |
| - name: Remove test container | |
| if: always() | |
| run: | | |
| if docker inspect migrator-db >/dev/null 2>&1; then | |
| docker rm -fv migrator-db | |
| fi | |
| coverage: | |
| name: Code coverage and PR comparison | |
| needs: test | |
| runs-on: ubuntu-22.04 | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| actions: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: test-results-* | |
| path: TestResults | |
| - run: python3 .github/scripts/verify-test-coverage.py TestResults | |
| - run: python3 .github/scripts/test-code-coverage.py | |
| - uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 9.0.x | |
| - name: Merge coverage and generate HTML report | |
| run: | | |
| dotnet tool install dotnet-reportgenerator-globaltool --version 5.4.18 --tool-path "$RUNNER_TEMP/reportgenerator" | |
| "$RUNNER_TEMP/reportgenerator/reportgenerator" '-reports:TestResults/*/coverage/coverage.cobertura.xml' '-targetdir:artifacts/coverage' '-reporttypes:Html;Cobertura' | |
| - name: Find coverage for the exact PR base commit | |
| if: github.event_name == 'pull_request' | |
| id: baseline | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const base = context.payload.pull_request.base; | |
| // Only trust reports from successful push/manual runs in this repository. | |
| const runs = await github.paginate(github.rest.actions.listWorkflowRuns, { | |
| ...context.repo, workflow_id: 'dotnetpull.yml', head_sha: base.sha, | |
| status: 'success', per_page: 100 | |
| }); | |
| for (const run of runs) { | |
| if (!['push', 'workflow_dispatch'].includes(run.event) || run.head_branch !== base.ref) continue; | |
| const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, { | |
| ...context.repo, run_id: run.id, per_page: 100 | |
| }); | |
| if (artifacts.some(a => a.name === 'code-coverage' && !a.expired)) { | |
| core.setOutput('run-id', String(run.id)); | |
| break; | |
| } | |
| } | |
| - name: Download baseline coverage | |
| if: steps.baseline.outputs.run-id != '' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: code-coverage | |
| path: artifacts/baseline | |
| github-token: ${{ github.token }} | |
| run-id: ${{ steps.baseline.outputs.run-id }} | |
| - name: Write coverage and delta to the PR check summary | |
| env: | |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| HEAD_SHA: ${{ github.sha }} | |
| run: python3 .github/scripts/summarize-code-coverage.py | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: code-coverage | |
| path: artifacts/coverage/ | |
| if-no-files-found: error | |
| retention-days: 90 |