Skip to content

Commit b1d517e

Browse files
gnodetclaude
andcommitted
CAMEL-23274: Add incremental coverage to SonarCloud PR analysis
Build on top of the core coverage baseline by adding per-module coverage for PR-affected components using the incremental-build action. Changes: - parent/pom.xml: Add jacoco:report goal to coverage profile so each tested module generates its own XML report - pom.xml: Update sonar.coverage.jacoco.xmlReportPaths to include both per-module and aggregated report paths - sonar-build.yml: Add incremental-build step with -Dcoverage in MVND_OPTS to test PR-affected modules with JaCoCo Coverage strategy: - Core: aggregated report via coverage module (camel-core tests exercise classes across multiple core source modules) - Components: per-module reports (each component's tests cover its own classes) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d203a34 commit b1d517e

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

.github/workflows/sonar-build.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ concurrency:
3737

3838
jobs:
3939
build:
40-
# Temporarily disabled until SonarCloud quality gate is adjusted (INFRA-27808)
41-
if: false && github.repository == 'apache/camel'
40+
if: github.repository == 'apache/camel'
4241
name: Build for Sonar Analysis
4342
runs-on: ubuntu-latest
4443
steps:
@@ -60,17 +59,27 @@ jobs:
6059
run: ./mvnw install -B -Dquickly
6160

6261
# Run core tests with JaCoCo and generate aggregated coverage report.
63-
# The source modules must be in the reactor so report-aggregate can
64-
# map execution data from camel-core tests to their classes.
65-
# TODO: Once incremental-build.sh supports module detection in the sonar
66-
# workflow, replace the hardcoded -pl with detected affected modules
67-
# to get coverage on components too (see PR #22247).
68-
- name: Run tests with coverage and generate report
62+
# Core modules need the aggregated report because camel-core tests
63+
# exercise classes from camel-core-model, camel-core-processor, etc.
64+
- name: Run core tests with coverage
6965
run: >
7066
./mvnw verify -B -Dcoverage
7167
-pl core/camel-api,core/camel-util,core/camel-support,core/camel-management-api,core/camel-management,core/camel-base,core/camel-base-engine,core/camel-core-engine,core/camel-core-languages,core/camel-core-model,core/camel-core-processor,core/camel-core-reifier,core/camel-core,coverage
7268
-Dmaven.test.failure.ignore=true
7369
70+
# Run tests on PR-affected modules with JaCoCo coverage.
71+
# Each component module generates its own per-module report
72+
# (target/site/jacoco/jacoco.xml) covering its own classes.
73+
- name: Run incremental tests with coverage
74+
uses: ./.github/actions/incremental-build
75+
with:
76+
pr-id: ${{ github.event.pull_request.number }}
77+
github-token: ${{ secrets.GITHUB_TOKEN }}
78+
artifact-upload-suffix: sonar
79+
env:
80+
MVND_OPTS: "-Dcoverage -Dmaven.test.failure.ignore=true"
81+
82+
7483
- name: Prepare compiled classes artifact
7584
shell: bash
7685
run: find . -name "target" -type d | tar -czf target.tar.gz -T -

parent/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4496,6 +4496,13 @@
44964496
</excludes>
44974497
</configuration>
44984498
</execution>
4499+
<execution>
4500+
<id>report</id>
4501+
<phase>verify</phase>
4502+
<goals>
4503+
<goal>report</goal>
4504+
</goals>
4505+
</execution>
44994506
</executions>
45004507
</plugin>
45014508
<plugin>

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@
122122

123123
<sonar.java.source>${jdk.version}</sonar.java.source>
124124
<!-- NOTE: this is required to correctly map each module coverage in Sonarqube. The ${maven.multiModuleProjectDirectory} may require some change
125-
when upgrading to Maven 4.x, according to any of the new variables that will replace this one. -->
125+
when upgrading to Maven 4.x, according to any of the new variables that will replace this one.
126+
Two sources: per-module reports (from jacoco:report) and the aggregated report (from coverage module). -->
126127
<sonar.coverage.jacoco.xmlReportPaths>
127-
${maven.multiModuleProjectDirectory}/coverage/target/site/jacoco-aggregate/jacoco.xml
128+
${project.build.directory}/site/jacoco/jacoco.xml,${maven.multiModuleProjectDirectory}/coverage/target/site/jacoco-aggregate/jacoco.xml
128129
</sonar.coverage.jacoco.xmlReportPaths>
129130

130131
<cyclonedx-maven-plugin-version>2.9.1</cyclonedx-maven-plugin-version>

0 commit comments

Comments
 (0)