Skip to content

Commit a52532d

Browse files
authored
Add Jacoco code coverage violation rules (#533)
This commit adds Jacoco violation rules as well as the following: - fails the PR workflow if rules are violated - uploads the report if the rules are violated - replaces JacocoConventionsPlugin (Java) with a simple groovy script Resolves #511
1 parent 653196f commit a52532d

File tree

7 files changed

+55
-46
lines changed

7 files changed

+55
-46
lines changed

.github/workflows/ci-pr.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,26 @@ jobs:
3737
- name: Build and run unit tests
3838
run: |
3939
./gradlew clean build -x integrationTest --continue --scan
40+
- name: Upload Test Results
41+
if: failure()
42+
uses: actions/upload-artifact@v3
43+
with:
44+
name: test-results
45+
path: '*/build/reports/tests/**/*.*'
46+
retention-days: 3
4047
- name: Create Aggregated Jacoco Report
41-
if: contains(github.event.pull_request.labels.*.name, 'ci/upload-jacoco')
4248
run: |
4349
./gradlew aggregateJacocoTestReport --info
50+
- name: Verify Code Coverage
51+
run: |
52+
./gradlew jacocoTestCoverageVerification --info
4453
- name: Upload Aggregated Jacoco Report
45-
if: contains(github.event.pull_request.labels.*.name, 'ci/upload-jacoco')
54+
if: failure() || contains(github.event.pull_request.labels.*.name, 'ci/upload-jacoco')
4655
uses: actions/upload-artifact@v3
4756
with:
4857
name: jacoco-results
4958
path: 'build/reports/jacoco/**/*.*'
5059
retention-days: 3
51-
- name: Capture Test Results
52-
if: failure()
53-
uses: actions/upload-artifact@v3
54-
with:
55-
name: test-results
56-
path: '*/build/reports/tests/**/*.*'
57-
retention-days: 3
5860
integration_tests:
5961
needs: [prerequisites, build_and_verify]
6062
runs-on: ubuntu-latest

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99

1010
description = 'Spring for Apache Pulsar'
1111

12+
apply from: 'gradle/jacoco-conventions.gradle'
1213
apply from: 'gradle/aggregate-jacoco-report.gradle'
1314
apply from: 'gradle/update-copyrights.gradle'
1415
apply from: 'gradle/version-catalog-update.gradle'

buildSrc/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ gradlePlugin {
5959
id = "io.spring.convention.artfiactory"
6060
implementationClass = "io.spring.gradle.convention.ArtifactoryPlugin"
6161
}
62-
jacocoConventionsPlugin {
63-
id = "org.springframework.pulsar.jacoco"
64-
implementationClass = "org.springframework.pulsar.gradle.check.JacocoConventionsPlugin"
65-
}
6662
optionalDependenciesPlugin {
6763
id = "org.springframework.pulsar.optional-dependencies"
6864
implementationClass = "org.springframework.pulsar.gradle.optional.OptionalDependenciesPlugin"

buildSrc/src/main/java/org/springframework/pulsar/gradle/SpringModulePlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.gradle.api.Project;
2020
import org.gradle.api.plugins.PluginManager;
2121

22-
import org.springframework.pulsar.gradle.check.JacocoConventionsPlugin;
2322
import org.springframework.pulsar.gradle.publish.PublishAllJavaComponentsPlugin;
2423
import org.springframework.pulsar.gradle.publish.SpringMavenPlugin;
2524

@@ -33,6 +32,5 @@ protected void additionalPlugins(Project project) {
3332
PluginManager pluginManager = project.getPluginManager();
3433
pluginManager.apply(SpringMavenPlugin.class);
3534
pluginManager.apply(PublishAllJavaComponentsPlugin.class);
36-
pluginManager.apply(JacocoConventionsPlugin.class);
3735
}
3836
}

buildSrc/src/main/java/org/springframework/pulsar/gradle/check/JacocoConventionsPlugin.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

dummy.file

Whitespace-only changes.

gradle/jacoco-conventions.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
def javaProjects = [ 'spring-pulsar',
2+
'spring-pulsar-cache-provider',
3+
'spring-pulsar-cache-provider-caffeine',
4+
'spring-pulsar-reactive',
5+
'spring-pulsar-test' ]
6+
7+
8+
allprojects {
9+
if (!javaProjects.contains(project.name)) {
10+
return
11+
}
12+
13+
apply plugin: 'jacoco'
14+
15+
jacoco {
16+
toolVersion libs.versions.jacoco.get()
17+
}
18+
19+
project.tasks.withType(Test, (test) ->
20+
project.tasks.withType(JacocoReport, test::finalizedBy))
21+
22+
tasks.withType(JacocoCoverageVerification) {
23+
violationRules {
24+
rule {
25+
limit {
26+
minimum = 0.5
27+
}
28+
}
29+
rule {
30+
enabled = false
31+
element = 'CLASS'
32+
includes = ['org.gradle.*']
33+
34+
limit {
35+
counter = 'LINE'
36+
value = 'TOTALCOUNT'
37+
maximum = 0.3
38+
}
39+
}
40+
}
41+
42+
}
43+
}

0 commit comments

Comments
 (0)