Skip to content

Commit

Permalink
Collect and Publish Test Coverage (Azure#14185)
Browse files Browse the repository at this point in the history
* Testing CodeCoverage collection and publishing

* Merge Code Coverage then Publish

* Add support for deterministic Builds

* Adjust Coverage Properties and set to run only on internal
  • Loading branch information
chidozieononiwu authored Aug 20, 2020
1 parent aec677f commit c0a4ef0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
23 changes: 23 additions & 0 deletions eng/CodeCoverage.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project>
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<PackageReference Include="coverlet.msbuild">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Allows Collection of Code Coverage for Deterministic Builds
https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/DeterministicBuild.md -->
<ItemGroup>
<SourceRoot Include="$(NuGetPackageRoot)" />
</ItemGroup>

<Target Name="CoverletGetPathMap"
DependsOnTargets="InitializeSourceRootMappedPaths"
Returns="@(_LocalTopLevelSourceRoot)"
Condition="'$(DeterministicSourcePaths)' == 'true'">
<ItemGroup>
<_LocalTopLevelSourceRoot Include="@(SourceRoot)" Condition="'%(SourceRoot.NestedRoot)' == ''"/>
</ItemGroup>
</Target>
</Project>
1 change: 1 addition & 0 deletions eng/Directory.Build.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<GenerateAPIListing Condition="'$(IsShippingClientLibrary)' == 'true'">true</GenerateAPIListing>
<UpdateSourceOnBuild Condition="'$(UpdateSourceOnBuild)' == ''">$(AZURE_DEV_UPDATESOURCESONBUILD)</UpdateSourceOnBuild>
<PowerShellExe Condition="'$(PowerShellExe)' == ''">pwsh</PowerShellExe>
<CoverletOutputFormat Condition="'$(CoverletOutputFormat)' == '' and '$(CollectCoverage)' == 'true'">cobertura</CoverletOutputFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(IsShippingClientLibrary)' == 'true' and '$(TF_BUILD)' == 'true'">
Expand Down
3 changes: 3 additions & 0 deletions eng/Directory.Build.Data.targets
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<None Condition="Exists('$(MSBuildProjectDirectory)/../README.md')" Include="$(MSBuildProjectDirectory)/../README.md" Pack="true" PackagePath=""/>
</ItemGroup>

<!-- Collect Code Coverage -->
<Import Condition="'$(CollectCoverage)' == 'true'" Project="$(MSBuildThisFileDirectory)\CodeCoverage.targets" />

<!-- Add StyleCop Analyzers -->
<ItemGroup Condition="'$(EnableStyleCopAnalyzers)' == 'true'" >
<PackageReference Include="StyleCop.Analyzers">
Expand Down
1 change: 1 addition & 0 deletions eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PackageReference Update="Azure.Storage.Blobs.ChangeFeed" Version="12.0.0-preview.1" />
<PackageReference Update="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Update="Castle.Core" Version="4.4.0" />
<PackageReference Update="coverlet.msbuild" Version="2.9.0" />
<PackageReference Update="FluentAssertions" Version="5.10.3" />
<PackageReference Update="FsCheck.Xunit" Version="2.14.0" />
<PackageReference Update="Microsoft.Azure.Amqp" Version="2.4.5" />
Expand Down
17 changes: 16 additions & 1 deletion eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ jobs:
Windows_NetCoreApp:
OSVmImage: "windows-2019"
TestTargetFramework: netcoreapp2.1
${{ if eq(variables['System.TeamProject'], 'internal') }}:
CollectCoverage: true
Windows_NetCoreApp_ProjectReferences:
OSVmImage: "windows-2019"
TestTargetFramework: netcoreapp2.1
Expand Down Expand Up @@ -159,7 +161,7 @@ jobs:
version: "$(DotNetCoreSDKVersion)"
- script: >-
dotnet test eng/service.proj --filter TestCategory!=Live --framework $(TestTargetFramework) --logger "trx;LogFileName=$(TestTargetFramework).trx" --logger:"console;verbosity=normal"
/p:ServiceDirectory=${{parameters.ServiceToBuild}} /p:IncludeSrc=false /p:IncludeSamples=false /p:Configuration=$(BuildConfiguration) $(ConvertToProjectReferenceOption)
/p:ServiceDirectory=${{parameters.ServiceToBuild}} /p:IncludeSrc=false /p:IncludeSamples=false /p:Configuration=$(BuildConfiguration) $(ConvertToProjectReferenceOption) /p:CollectCoverage=$(CollectCoverage)
displayName: "Build & Test ($(TestTargetFramework))"
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
Expand All @@ -173,3 +175,16 @@ jobs:
testRunTitle: "$(OSName) $(TestTargetFramework)"
testResultsFormat: "VSTest"
mergeTestResults: true
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
condition: and(succeeded(), eq(variables['CollectCoverage'], 'true'))
displayName: ReportGenerator
inputs:
reports: '**/*coverage.netcoreapp2.1.cobertura.xml'
targetdir: '$(Build.SourcesDirectory)'
reporttypes: Cobertura
- task: PublishCodeCoverageResults@1
condition: and(succeeded(), eq(variables['CollectCoverage'], 'true'))
displayName: 'Publish code coverage report'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: 'Cobertura.xml'
1 change: 1 addition & 0 deletions eng/pipelines/templates/variables/globals.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ variables:
${{ if eq(variables['System.TeamProject'], 'internal') }}:
BuildConfiguration: 'Release'
DocFxVersion: 'v2.56.1'
CollectCoverage: false

0 comments on commit c0a4ef0

Please sign in to comment.