Skip to content

Commit

Permalink
Enable build failure when code coverage is below threshold (#7228)
Browse files Browse the repository at this point in the history
* Enable build failure when code coverage is below threshold

* Remove comment

* Install reporting tools for verify goal

* Configurable coverage threshold
  • Loading branch information
srnagar authored Jan 8, 2020
1 parent 11cceb0 commit 0c2df36
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
43 changes: 41 additions & 2 deletions eng/pipelines/templates/jobs/archetype-sdk-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ parameters:
ServiceDirectory: not-specified # Set a default that breaks in obvious ways.
PreTestSteps: []
TestOptions: '$(DefaultOptions)'
TestGoals: test
TestGoals: verify
TestMatrix:
Linux - Java 8:
OSName: 'Linux'
Expand Down Expand Up @@ -274,6 +274,11 @@ jobs:

- template: ../steps/cache-maven-repository.yml

- template: ../steps/install-reporting-tools.yml
parameters:
Options: --batch-mode
MavenOptions: $(MemoryOptions) $(LoggingOptions)

- task: Maven@3
displayName: 'Start Jetty'
condition: ne(variables['SdkType'], 'client')
Expand Down Expand Up @@ -329,7 +334,7 @@ jobs:
jdkArchitectureOption: 'x64'
publishJUnitResults: false
goals: ${{ parameters.TestGoals }}
# we want to run this when TestFromSource isn't true (which covers normal running when it isn't set)
# we want to run this when TestFromSource isn't true (which covers normal running when it isn't set)
# OR when ShouldRunSourceTests is true
condition: and(succeeded(), or(ne(variables['TestFromSource'],'true'), eq(variables['ShouldRunSourceTests'],'true')))

Expand All @@ -338,3 +343,37 @@ jobs:
inputs:
mergeTestResults: true
testRunTitle: $(RunTitle)

# Generate JaCoCo code coverage report on Java 11, Linux builds if the build reason is not PR.
- task: Maven@3
displayName: 'Generate aggregate code coverage report'
condition: and(eq(variables['OsName'], 'Linux'), eq(variables['JavaVersion'], '1.11'), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
# Aggregate reports for non-PR builds will use pom.client.xml and include non-shipping modules
mavenPomFile: pom.client.xml
options: '$(DefaultOptions) -Dinclude-non-shipping-modules -Dgpg.skip -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotbugs.skip=true'
mavenOptions: '-Xmx3072m $(LoggingOptions)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: $(JavaVersion)
jdkArchitectureOption: 'x64'
publishJUnitResults: false
goals: 'verify'

# Azure DevOps only seems to respect the last code coverage result published, so only do this for Linux + Java LTS.
# Code coverage reporting is setup only for Track 2 modules.
- task: PublishCodeCoverageResults@1
condition: and(eq(variables['OsName'], 'Linux'), eq(variables['JavaVersion'], '1.11'), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
codeCoverageTool: JaCoCo
summaryFileLocation: eng/jacoco-test-coverage/target/site/test-coverage/jacoco.xml
reportDirectory: eng/jacoco-test-coverage/target/site/test-coverage/
failIfCoverageEmpty: true

# Publish code coverage to an artifact so it can be uploaded to the Maven site.
# Do this for track 2 modules only. Code coverage from previous step is only published for Linux + Java LTS.
- task: PublishPipelineArtifact@0
displayName: 'Publish coverage artifact'
condition: and(eq(variables['OsName'], 'Linux'), eq(variables['JavaVersion'], '1.11'), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
artifactName: coverage
targetPath: eng/jacoco-test-coverage/target/site/
27 changes: 27 additions & 0 deletions pom.client.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<site.url>https://azuresdkartifacts.blob.core.windows.net/azure-sdk-for-java</site.url>
<issues.url>https://github.com/Azure/azure-sdk-for-java/issues</issues.url>
<build.context>azure-client-sdk-parent</build.context>
<jacoco.min.linecoverage>0.40</jacoco.min.linecoverage>
<jacoco.min.branchcoverage>0.30</jacoco.min.branchcoverage>
</properties>

<build>
Expand Down Expand Up @@ -333,6 +335,31 @@
<outputDirectory>${project.reporting.outputDirectory}/test-coverage</outputDirectory>
</configuration>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.min.linecoverage}</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.min.branchcoverage}</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>

Expand Down
5 changes: 5 additions & 0 deletions sdk/storage/azure-storage-blob-cryptography/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<tag>HEAD</tag>
</scm>

<properties>
<jacoco.min.linecoverage>0.18</jacoco.min.linecoverage>
<jacoco.min.branchcoverage>0.09</jacoco.min.branchcoverage>
</properties>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
Expand Down
5 changes: 5 additions & 0 deletions sdk/storage/azure-storage-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
<tag>HEAD</tag>
</scm>

<properties>
<jacoco.min.linecoverage>0.20</jacoco.min.linecoverage>
<jacoco.min.branchcoverage>0.18</jacoco.min.branchcoverage>
</properties>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
Expand Down

0 comments on commit 0c2df36

Please sign in to comment.