Skip to content

Commit 2fe8dba

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 2fe8dba

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

.github/actions/incremental-build/incremental-build.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,27 @@ main() {
544544
$mavenBinary -l "$log" $MVND_OPTS install -pl "$build_pl" || ret=$?
545545
fi
546546

547+
# ── Step 4b: Aggregated core coverage report ──
548+
# When coverage is enabled and core modules were tested, generate the
549+
# aggregated JaCoCo report via the coverage module. This is needed because
550+
# camel-core tests exercise classes from camel-core-model, camel-core-processor,
551+
# etc., so per-module reports alone miss cross-module coverage.
552+
if [[ "${MVND_OPTS:-}" == *"-Dcoverage"* ]]; then
553+
local core_tested=false
554+
for w in $(echo "$final_pl" | tr ',' '\n'); do
555+
if [[ "$w" == core/* ]]; then
556+
core_tested=true
557+
break
558+
fi
559+
done
560+
if [[ "$core_tested" == true ]]; then
561+
echo ""
562+
echo "Core modules affected — generating aggregated coverage report..."
563+
$mavenBinary verify -B -Dcoverage -pl coverage -am -DskipTests \
564+
|| echo "WARNING: Coverage aggregation failed (non-fatal)"
565+
fi
566+
fi
567+
547568
# ── Step 5: Write comment and summary ──
548569
local comment_file="incremental-test-comment.md"
549570
writeComment "$comment_file" "$pl" "$dep_module_ids" "$all_changed_props" "$testedDependents" "$extraModules"

.github/workflows/sonar-build.yml

Lines changed: 14 additions & 13 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:
@@ -59,17 +58,19 @@ jobs:
5958
- name: Build with Maven
6059
run: ./mvnw install -B -Dquickly
6160

62-
# 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
69-
run: >
70-
./mvnw verify -B -Dcoverage
71-
-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
72-
-Dmaven.test.failure.ignore=true
61+
# Run tests on PR-affected modules with JaCoCo coverage.
62+
# Per-module reports are generated by jacoco:report (added in parent pom).
63+
# When core modules are affected, the incremental build also generates
64+
# the aggregated coverage report via the coverage module.
65+
- name: Run incremental tests with coverage
66+
uses: ./.github/actions/incremental-build
67+
with:
68+
pr-id: ${{ github.event.pull_request.number }}
69+
github-token: ${{ secrets.GITHUB_TOKEN }}
70+
artifact-upload-suffix: sonar
71+
env:
72+
MVND_OPTS: "-Dcoverage -Dmaven.test.failure.ignore=true"
73+
7374

7475
- name: Prepare compiled classes artifact
7576
shell: bash

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)