Skip to content

Commit

Permalink
Automate code coverage report as part of PRs. (dotnet#2194)
Browse files Browse the repository at this point in the history
* Integrate coverlet for code coverage and upload reports to codecov.io
  • Loading branch information
codemzs authored Jan 23, 2019
1 parent 0b50407 commit 8e8b0c2
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Daily NuGet builds of the project are also available in our [MyGet](https://dotn

To build ML.NET from source please visit our [developers guide](docs/project-docs/developer-guide.md).

[![codecov](https://codecov.io/gh/dotnet/machinelearning/branch/master/graph/badge.svg)](https://codecov.io/gh/dotnet/machinelearning)

| | Debug | Release |
|:---|----------------:|------------------:|
|**Linux**|[![x64-debug](https://dnceng.visualstudio.com/public/_apis/build/status/dotnet/machinelearning/MachineLearning-CI?branchName=master&jobname=Linux&configuration=Build_Debug)](https://dnceng.visualstudio.com/DotNet-Public/_build/latest?definitionId=104&branch=master)|[![x64-release](https://dnceng.visualstudio.com/public/_apis/build/status/dotnet/machinelearning/MachineLearning-CI?branchName=master&jobname=Linux&configuration=Build_Release)](https://dnceng.visualstudio.com/DotNet-Public/_build/latest?definitionId=104&branch=master)|
Expand Down
37 changes: 37 additions & 0 deletions build/Codecoverage.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Codecov">

<PropertyGroup>
<!-- We need to specify a framework in order for the Restore target to work -->
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Codecov" Version="$(CodecovVersion)" />
</ItemGroup>
<Target Name="Codecov" DependsOnTargets="Restore">
<PropertyGroup>
<_CodecovPath>$(RestorePackagesPath)codecov\$(CodecovVersion)\tools\Codecov.exe</_CodecovPath>

<_BranchName Condition="'$(_BranchName)' == ''">$(SYSTEM_PULLREQUEST_TARGETBRANCH)</_BranchName>
<_BranchName Condition="'$(_BranchName)' == ''">$(BUILD_SOURCEBRANCHNAME)</_BranchName>
</PropertyGroup>

<ItemGroup>
<_CoverageReports Include="$(BaseOutputPath)$(PlatformConfig)\coverage\*.coverage" />

<_CodecovArgs Include="-f;@(_CoverageReports)" />
<_CodecovArgs Include="-r;$(BUILD_REPOSITORY_NAME)" Condition="'$(BUILD_REPOSITORY_NAME)' != ''" />
<_CodecovArgs Include="--pr;$(SYSTEM_PULLREQUEST_PULLREQUESTNUMBER)" Condition="'$(SYSTEM_PULLREQUEST_PULLREQUESTNUMBER)' != ''" />
<_CodecovArgs Include="-b;$(BUILD_BUILDNUMBER)" Condition="'$(BUILD_BUILDNUMBER)' != ''" />
<_CodecovArgs Include="--branch;$(_BranchName)" Condition="'$(_BranchName)' != ''" />
<_CodecovArgs Include="-c;$(BUILD_SOURCEVERSION)" Condition="'$(BUILD_SOURCEVERSION)' != ''" />
<_CodecovArgs Include="-n;$(BUILD_DEFINITIONNAME)" Condition="'$(BUILD_DEFINITIONNAME)' != ''" />
<_CodecovArgs Include="--flag;$(Configuration)" Condition="'$(Configuration)' != ''" />
<_CodecovArgs Include="-t;$(CodeCovToken)" Condition="'$(CodeCovToken)' != ''" />
</ItemGroup>

<Message Importance="high" Text="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ')" />
<Exec Command="&quot;$(_CodecovPath)&quot; @(_CodecovArgs, ' ')" />
</Target>

</Project>
2 changes: 2 additions & 0 deletions build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
<!-- Build/infrastructure Dependencies -->
<PropertyGroup>
<PublishSymbolsPackageVersion>1.0.0-beta-62824-02</PublishSymbolsPackageVersion>
<CodecovVersion>1.1.1</CodecovVersion>
<CoverletVersion>2.5.1</CoverletVersion>
</PropertyGroup>

<!-- Test-only Dependencies -->
Expand Down
9 changes: 7 additions & 2 deletions build/ci/phase-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ parameters:
buildScript: ''
queue: {}
customMatrixes: ''
codeCoverage: false

phases:
- phase: ${{ parameters.name }}
variables:
_buildScript: ${{ parameters.buildScript }}
_phaseName: ${{ parameters.name }}
_arch: ${{ parameters.architecture }}
_codeCoverage: ${{ parameters.codeCoverage }}
queue:
timeoutInMinutes: 45
parallel: 99
Expand All @@ -35,8 +37,11 @@ phases:
- ${{ if eq(parameters.name, 'MacOS') }}:
- script: brew update && brew install libomp mono-libgdiplus gettext && brew link gettext --force
displayName: Install runtime dependencies
- script: $(_buildScript) -$(_configuration) -runtests
displayName: Run Tests
- script: $(_buildScript) -$(_configuration) -runtests -coverage=$(_codeCoverage)
displayName: Run Tests.
- script: $(Build.SourcesDirectory)/Tools/dotnetcli/dotnet msbuild build/Codecoverage.proj /p:CodeCovToken=$(CODECOV_TOKEN)
displayName: Upload coverage to codecov.io
condition: eq(variables._codeCoverage, 'true')
- task: PublishTestResults@2
displayName: Publish Test Results
condition: succeededOrFailed()
Expand Down
17 changes: 17 additions & 0 deletions build/codecoverage-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
################################################################################
# ML.NET's Code Coverage validation build
################################################################################

phases:
- template: /ci/phase-template.yml
parameters:
name: Windows_x64
buildScript: build.cmd
customMatrixes:
Build_Debug:
_configuration: Debug
_config_short: D
_includeBenchmarkData: false
codeCoverage: true
queue:
name: Hosted VS2017
20 changes: 20 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# https://docs.codecov.io/docs/codecov-yaml
# https://github.com/codecov/support/wiki/Codecov-Yaml

coverage:
status:
project:
default: false
patch:
default: false

comment:
layout: "diff"

flags:
production:
paths:
- src/
test:
paths:
- test/
6 changes: 6 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
"values": [],
"defaultValue": ""
},
"Coverage": {
"description": "Turn on code coverge.",
"valueType": "property",
"values": ["false", "true"],
"defaultValue": "false"
},
"CleanAllProjects": {
"description": "MsBuild target that deletes the binary output directory.",
"valueType": "target",
Expand Down
13 changes: 13 additions & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Microsoft.DotNet.XUnitExtensions" Version="2.4.0-prerelease-63213-02" />
<PackageReference Include="coverlet.msbuild" Version="$(CoverletVersion)" />
</ItemGroup>

<PropertyGroup Condition="'$(Coverage)' == 'true'">
<CollectCoverage>true</CollectCoverage>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <!-- https://github.com/tonerdo/coverlet/issues/72 -->
<CoverletOutputFormat>opencover</CoverletOutputFormat>
<CoverletOutput>$(BaseOutputPath)$(PlatformConfig)\coverage\$(MSBuildProjectName).coverage</CoverletOutput>
<Include>[Microsoft.ML.*]*</Include>
<!-- Excluding for perf reasons. These classes have tests that can be run conditionally
but they need to be migrated. Excluding these classes should have very minimal effect on code coverage.
-->
<Exclude>[*]Microsoft.ML.*Contracts*,[*]Microsoft.ML.Internal.Utilities*,[*]Microsoft.ML.Data.VBuffer*</Exclude>
</PropertyGroup>

</Project>

0 comments on commit 8e8b0c2

Please sign in to comment.