Skip to content

Commit

Permalink
Do not generate reports with no coverage (Azure#17293)
Browse files Browse the repository at this point in the history
  • Loading branch information
heaths authored and annelo-msft committed Feb 17, 2021
1 parent e120d40 commit 97fa855
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
22 changes: 20 additions & 2 deletions eng/CodeCoverage.targets
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,34 @@
</ItemGroup>

<!-- Clean up previous TestResults so reports are recent. -->
<Target Name="CleanPreviousCodeCoverage"
<Target Name="_CleanPreviousCodeCoverage"
BeforeTargets="VSTest"
Condition="'$(_CollectCoverage)' == 'true'">
<RemoveDir Directories="$(_TestResultsDirectory)" />
</Target>

<!-- Set a variable to indicate that a report can be generated. -->
<Target Name="_SetCoverageCollected"
AfterTargets="VSTest"
Condition="'$(_CollectCoverage)' == 'true'">
<ItemGroup>
<_CoverageFiles Include="$(_TestResultsDirectory)\**\coverage.cobertura.xml" />
</ItemGroup>
<PropertyGroup>
<_CoverageCollected Condition="'@(_CoverageFiles)' != ''">true</_CoverageCollected>
</PropertyGroup>

<!-- Indicate to the pipeline a report can be generated. -->
<Message Importance="high"
Condition="'$(_CoverageCollected)' == 'true' and '$(TF_BUILD)' == 'true'"
Text="##vso[task.setvariable variable=coverage.collected]true" />
</Target>

<!-- Should be similar to what's in the pipelines, though generate a full HTML report. -->
<Target Name="GenerateCodeCoverageReport"
AfterTargets="VSTest"
Condition="'$(_CollectCoverage)' == 'true' and '$(SkipCoverageReport)' != 'true'">
DependsOnTargets="_SetCoverageCollected"
Condition="'$(_CollectCoverage)' == 'true' and '$(SkipCoverageReport)' != 'true' and '$(_CoverageCollected)' == 'true'">
<PropertyGroup>
<CoverageReportCommandLine>dotnet tool run reportgenerator --</CoverageReportCommandLine>
<CoverageReportCommandLine>$(CoverageReportCommandLine) "-reports:$(_TestResultsDirectory)\**\coverage.cobertura.xml"</CoverageReportCommandLine>
Expand Down
9 changes: 3 additions & 6 deletions eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ jobs:
condition: and(succeededOrFailed(), ne(variables['Skip.Test'], true))
variables:
- template: ../variables/globals.yml
- name: disable.coverage.autogenerate
value: true
strategy:
maxParallel: $[ variables['MaxParallelTestJobs'] ]
matrix:
Expand Down Expand Up @@ -167,18 +165,17 @@ jobs:
testResultsFormat: "VSTest"
mergeTestResults: true
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
condition: and(succeededOrFailed(), eq(variables['CollectCoverage'], 'true'))
condition: and(succeededOrFailed(), eq(variables['CollectCoverage'], 'true'), eq(variables['coverage.collected'], 'true'))
displayName: Generate Code Coverage Reports
inputs:
reports: $(Build.SourcesDirectory)\sdk\${{parameters.ServiceDirectory}}\**\coverage.cobertura.xml
targetdir: $(Build.ArtifactStagingDirectory)\coverage
reporttypes: Cobertura;HtmlInline_AzurePipelines
reporttypes: Cobertura
filefilters: +$(Build.SourcesDirectory)\sdk\${{parameters.ServiceDirectory}}\**
verbosity: Verbose
- task: PublishCodeCoverageResults@1
condition: and(succeededOrFailed(), eq(variables['CollectCoverage'], 'true'))
condition: and(succeededOrFailed(), eq(variables['CollectCoverage'], 'true'), eq(variables['coverage.collected'], 'true'))
displayName: Publish Code Coverage Reports
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Build.ArtifactStagingDirectory)\coverage\Cobertura.xml
reportDirectory: $(Build.ArtifactStagingDirectory)\coverage

0 comments on commit 97fa855

Please sign in to comment.