Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable build failure when code coverage is below threshold #7228

Merged
merged 4 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JonathanGiles is this particular change going to require us to up the version and re-release the parent pom?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JimSuplizio since this change only introduces a check to fail the build when test coverage is low, it's not end user-facing. So, version update and re-release is not necessary.

<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