Skip to content

Commit

Permalink
feat: add dotnet code coverage (#5403)
Browse files Browse the repository at this point in the history
  • Loading branch information
bassmang authored Feb 6, 2025
1 parent ca42891 commit da6f918
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 58 deletions.
95 changes: 38 additions & 57 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ jobs:
- name: workflows has changes
run: echo "workflows has changes"
if: steps.filter.outputs.workflows == 'true'

build:
name: Dotnet Build
name: Dotnet Build & Test
needs: paths-filter
if: needs.paths-filter.outputs.hasChanges == 'true'
defaults:
Expand All @@ -64,35 +65,12 @@ jobs:
- uses: actions/checkout@v4
with:
lfs: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install jupyter and ipykernel
run: |
python -m pip install --upgrade pip
python -m pip install jupyter
python -m pip install ipykernel
- name: list available kernels
run: |
python -m jupyter kernelspec list
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
version: "0.5.18"
- run: uv sync --locked --all-extras
working-directory: ./python
- name: Prepare python venv
run: |
source ${{ github.workspace }}/python/.venv/bin/activate
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: |
# dotnet nuget add source --name dotnet-tool https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json --configfile NuGet.config
dotnet restore -bl
run: dotnet restore -bl
- name: Format check
run: |
echo "Format check"
Expand All @@ -104,40 +82,43 @@ jobs:
dotnet build --no-restore --configuration Release -bl /p:SignAssembly=true
- name: Unit Test V1
run: dotnet test --no-build -bl --configuration Release --filter "Category=UnitV1"
- name: Unit Test V2
run: dotnet test --no-build -bl --configuration Release --filter "Category=UnitV2"

grpc-unit-tests:
name: Dotnet Grpc unit tests
needs: paths-filter
if: needs.paths-filter.outputs.hasChanges == 'true'
defaults:
run:
working-directory: dotnet
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Unit Test V2 (With Coverage)
run: dotnet test --no-build -bl --configuration Release --filter "Category=UnitV2" --collect:"XPlat Code Coverage"
- name: Install Dev Certs for GRPC
if: matrix.os == 'ubuntu-latest'
run: dotnet dev-certs https --trust
- name: GRPC Tests (With Coverage)
if: matrix.os == 'ubuntu-latest'
run: dotnet test --no-build -bl --configuration Release --filter "Category=GRPC" --collect:"XPlat Code Coverage"
- name: Generate & Merge Coverage Report
if: matrix.os == 'ubuntu-latest'
run: |
# Install reportgenerator
dotnet tool install -g dotnet-reportgenerator-globaltool || dotnet tool update -g dotnet-reportgenerator-globaltool
# Ensure output directory exists
mkdir -p ${{ github.workspace }}/dotnet/coverage-report
# Merge all coverage reports and generate HTML + XML
reportgenerator \
-reports:${{ github.workspace }}/dotnet/**/TestResults/**/coverage.cobertura.xml \
-targetdir:${{ github.workspace }}/dotnet/coverage-report \
-reporttypes:"Cobertura;Html"
ls -R ${{ github.workspace }}/dotnet/coverage-report
- name: Upload Merged Coverage Report
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
lfs: true
- name: Setup .NET 8.0
uses: actions/setup-dotnet@v4
name: CodeCoverageReport
path: ${{ github.workspace }}/dotnet/coverage-report/
retention-days: 7
- name: Upload Coverage to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v5
with:
dotnet-version: '8.0.x'
- name: Install dev certs
run: dotnet --version && dotnet dev-certs https --trust
- name: Restore dependencies
run: |
# dotnet nuget add source --name dotnet-tool https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json --configfile NuGet.config
dotnet restore -bl
- name: Build
run: dotnet build --no-restore --configuration Release -bl /p:SignAssembly=true
- name: GRPC tests
run: dotnet test --no-build -bl --configuration Release --filter "Category=GRPC"
files: ${{ github.workspace }}/dotnet/coverage-report/*.xml
flags: unittests
name: dotnet-codecov
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

integration-test:
strategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<ProjectReference Include="..\..\src\Microsoft.AutoGen\Core\Microsoft.AutoGen.Core.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AutoGen\Core.Grpc\Microsoft.AutoGen.Core.Grpc.csproj" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<ProjectReference Include="..\..\src\Microsoft.AutoGen\Core\Microsoft.AutoGen.Core.csproj" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Microsoft.AutoGen.Runtime.Grpc.Tests;
[Collection(ClusterCollection.Name)]
[Trait("Category", "UnitV2")]
[Trait("Category", "GRPC")]
public class GrpcGatewayServiceTests
{
private readonly ClusterFixture _fixture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
<PackageReference Include="Microsoft.Orleans.TestingHost" />
</ItemGroup>
Expand Down

0 comments on commit da6f918

Please sign in to comment.