diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9bd3bfa1..eb1c67ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: if: github.event_name != 'merge_group' permissions: contents: read + code-quality: write + pull-requests: read uses: ./.github/workflows/reusable-coverage.yml secrets: codecov-token: ${{ secrets.CODECOV_UPLOAD_TOKEN }} diff --git a/.github/workflows/reusable-build.yml b/.github/workflows/reusable-build.yml index 68fa9004..e459d858 100644 --- a/.github/workflows/reusable-build.yml +++ b/.github/workflows/reusable-build.yml @@ -37,7 +37,7 @@ jobs: run: dotnet build -c Release --no-restore - name: Test - run: dotnet test -c Release --no-build --report-github --ignore-exit-code 8 + run: dotnet test -c Release --no-build --report-gh --ignore-exit-code 8 - name: aot-publish test run: dotnet publish ./samples/AspNetCore/Samples.AspNetCore.csproj diff --git a/.github/workflows/reusable-coverage.yml b/.github/workflows/reusable-coverage.yml index d76eeb7e..60d142bc 100644 --- a/.github/workflows/reusable-coverage.yml +++ b/.github/workflows/reusable-coverage.yml @@ -13,6 +13,8 @@ jobs: permissions: contents: read + pull-requests: read + code-quality: write strategy: matrix: @@ -25,13 +27,15 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: fetch-depth: 0 + # Check out the PR head commit (not the merge commit) so coverage line numbers map to the diff + ref: ${{ github.event.pull_request.head.sha || github.sha }} persist-credentials: false - name: Setup .NET uses: ./.github/actions/setup-dotnet - name: Run Test - run: dotnet test --coverlet --coverlet-output-format opencover --coverlet-exclude "[GitHubActionsTestLogger*]*" --ignore-exit-code 8 + run: dotnet test --coverlet --coverlet-output-format opencover cobertura --ignore-exit-code 8 # Keep globbing on non-Windows runners (works today) - name: Upload coverage to Codecov (non-Windows) @@ -69,3 +73,29 @@ jobs: fail_ci_if_error: true verbose: true token: ${{ secrets.codecov-token }} + + # GitHub's code coverage API takes a single Cobertura file, so merge the per-project/per-TFM reports. + # Paths are rewritten to be repository-relative so coverage maps onto the files in the diff. + - name: Merge Cobertura reports (Linux) + if: runner.os == 'Linux' + run: | + dotnet tool install --global dotnet-reportgenerator-globaltool --version 5.5.11 + export PATH="$PATH:$HOME/.dotnet/tools" + reportgenerator \ + -reports:"**/coverage.cobertura.*.xml" \ + -targetdir:"coverage-report" \ + -reporttypes:Cobertura \ + -filefilters:"-**/obj/**" + sed -i -e "s#${GITHUB_WORKSPACE}/##g" \ + -e "s#[^<]*#.#g" \ + coverage-report/Cobertura.xml + + - name: Upload coverage to GitHub (Linux) + if: runner.os == 'Linux' + uses: actions/upload-code-coverage@1c15be36fc3733ba839b1dd643bd9556e4426dc1 # v1.4.1 + with: + file: coverage-report/Cobertura.xml + language: C# + label: code-coverage/coverlet + # Best effort: a coverage-service outage must never block CI. Codecov remains the gate. + fail-on-error: false diff --git a/.github/workflows/reusable-e2e.yml b/.github/workflows/reusable-e2e.yml index e6c73527..76d4e193 100644 --- a/.github/workflows/reusable-e2e.yml +++ b/.github/workflows/reusable-e2e.yml @@ -27,4 +27,4 @@ jobs: run: cp spec/specification/assets/gherkin/*.feature test/OpenFeature.E2ETests/Features/ - name: Run Tests - run: dotnet test test/OpenFeature.E2ETests/ --configuration Release --report-github + run: dotnet test test/OpenFeature.E2ETests/ --configuration Release --report-gh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 951a89f0..f47c6139 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -84,7 +84,7 @@ dotnet test test/OpenFeature.Tests/ To run unit tests with code coverage execute: ```bash -dotnet test test/OpenFeature.Tests/ --coverlet --coverlet-output-format opencover +dotnet test test/OpenFeature.Tests/ --coverlet --coverlet-output-format opencover cobertura ``` #### E2E tests diff --git a/Directory.Packages.props b/Directory.Packages.props index 3159b444..9d78eea7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -35,10 +35,10 @@ - + diff --git a/build/Common.tests.props b/build/Common.tests.props index 054ad94d..2c1b3635 100644 --- a/build/Common.tests.props +++ b/build/Common.tests.props @@ -20,8 +20,8 @@ - - + +