diff --git a/.github/workflows/validate-and-package.yml b/.github/workflows/validate-and-package.yml index 01a037d..87809cc 100644 --- a/.github/workflows/validate-and-package.yml +++ b/.github/workflows/validate-and-package.yml @@ -28,6 +28,16 @@ jobs: build-test-package: runs-on: windows-latest + # `code-quality: write` lets the run upload the Cobertura report to + # GitHub Code Quality so coverage shows up on the PR. `pull-requests: read` + # is required because same-repo PRs on `main`/`rel/*`/`dev/**` branches are + # served by the `push` event run (see the `if` below), and on `push` the + # upload action resolves the open PR via `gh pr list`. + permissions: + contents: read + code-quality: write + pull-requests: read + # A push to a branch with an open PR fires both `push` and `pull_request` # events. Rather than cancelling one of them (a cancelled run reports # as a failed required check on the PR's head SHA and blocks merge), @@ -187,7 +197,7 @@ jobs: dotnet tool run reportgenerator ` "-reports:$reports" ` "-targetdir:TestResults/coverage" ` - "-reporttypes:Html;MarkdownSummaryGithub;TextSummary" ` + "-reporttypes:Html;MarkdownSummaryGithub;TextSummary;Cobertura" ` "-title:CosmosDBShell Code Coverage" if ($LASTEXITCODE -ne 0) { throw "reportgenerator failed with exit code $LASTEXITCODE." @@ -198,6 +208,24 @@ jobs: Get-Content $markdown | Out-File -FilePath $env:GITHUB_STEP_SUMMARY -Encoding utf8 -Append } + # Publish coverage to GitHub Code Quality so the aggregate percentage and + # per-file breakdown appear directly on the PR (public preview feature). + # ReportGenerator merges the per-project XPlat reports into a single + # Cobertura.xml that this action uploads. Skipped for fork PRs, which + # cannot write to the base repo; `fail-on-error: false` keeps CI green if + # Code Quality is not yet enabled on the repository. + - name: Upload coverage to GitHub Code Quality + if: >- + always() && + (github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name == github.repository) + uses: actions/upload-code-coverage@v1 + with: + file: TestResults/coverage/Cobertura.xml + language: C# + label: code-coverage/dotnet + fail-on-error: false + - name: Upload code coverage report if: always() uses: actions/upload-artifact@v4