From 2dbee5f6d535a6f56b4da34677f08333f8316491 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 7 Apr 2026 13:35:57 +0200 Subject: [PATCH] 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 --- .../incremental-build/incremental-build.sh | 21 +++++++++++++++ .github/workflows/sonar-build.yml | 27 ++++++++++--------- parent/pom.xml | 7 +++++ pom.xml | 5 ++-- 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/.github/actions/incremental-build/incremental-build.sh b/.github/actions/incremental-build/incremental-build.sh index 1938b7c8cefb5..3109540cd8be7 100755 --- a/.github/actions/incremental-build/incremental-build.sh +++ b/.github/actions/incremental-build/incremental-build.sh @@ -544,6 +544,27 @@ main() { $mavenBinary -l "$log" $MVND_OPTS install -pl "$build_pl" || ret=$? fi + # ── Step 4b: Aggregated core coverage report ── + # When coverage is enabled and core modules were tested, generate the + # aggregated JaCoCo report via the coverage module. This is needed because + # camel-core tests exercise classes from camel-core-model, camel-core-processor, + # etc., so per-module reports alone miss cross-module coverage. + if [[ "${MVND_OPTS:-}" == *"-Dcoverage"* ]]; then + local core_tested=false + for w in $(echo "$final_pl" | tr ',' '\n'); do + if [[ "$w" == core/* ]]; then + core_tested=true + break + fi + done + if [[ "$core_tested" == true ]]; then + echo "" + echo "Core modules affected — generating aggregated coverage report..." + $mavenBinary verify -B -Dcoverage -pl coverage -am -DskipTests \ + || echo "WARNING: Coverage aggregation failed (non-fatal)" + fi + fi + # ── Step 5: Write comment and summary ── local comment_file="incremental-test-comment.md" writeComment "$comment_file" "$pl" "$dep_module_ids" "$all_changed_props" "$testedDependents" "$extraModules" diff --git a/.github/workflows/sonar-build.yml b/.github/workflows/sonar-build.yml index 9b1e990af7213..9a0456aaa2fe9 100644 --- a/.github/workflows/sonar-build.yml +++ b/.github/workflows/sonar-build.yml @@ -37,8 +37,7 @@ concurrency: jobs: build: - # Temporarily disabled until SonarCloud quality gate is adjusted (INFRA-27808) - if: false && github.repository == 'apache/camel' + if: github.repository == 'apache/camel' name: Build for Sonar Analysis runs-on: ubuntu-latest steps: @@ -59,17 +58,19 @@ jobs: - name: Build with Maven run: ./mvnw install -B -Dquickly - # Run core tests with JaCoCo and generate aggregated coverage report. - # The source modules must be in the reactor so report-aggregate can - # map execution data from camel-core tests to their classes. - # TODO: Once incremental-build.sh supports module detection in the sonar - # workflow, replace the hardcoded -pl with detected affected modules - # to get coverage on components too (see PR #22247). - - name: Run tests with coverage and generate report - run: > - ./mvnw verify -B -Dcoverage - -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 - -Dmaven.test.failure.ignore=true + # Run tests on PR-affected modules with JaCoCo coverage. + # Per-module reports are generated by jacoco:report (added in parent pom). + # When core modules are affected, the incremental build also generates + # the aggregated coverage report via the coverage module. + - name: Run incremental tests with coverage + uses: ./.github/actions/incremental-build + with: + pr-id: ${{ github.event.pull_request.number }} + github-token: ${{ secrets.GITHUB_TOKEN }} + artifact-upload-suffix: sonar + env: + MVND_OPTS: "-Dcoverage -Dmaven.test.failure.ignore=true" + - name: Prepare compiled classes artifact shell: bash diff --git a/parent/pom.xml b/parent/pom.xml index aaa98edbecc75..2a083f2166310 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -4502,6 +4502,13 @@ + + report + verify + + report + + diff --git a/pom.xml b/pom.xml index 45a0450e6a12f..8a55e8be9956d 100644 --- a/pom.xml +++ b/pom.xml @@ -122,9 +122,10 @@ ${jdk.version} + when upgrading to Maven 4.x, according to any of the new variables that will replace this one. + Two sources: per-module reports (from jacoco:report) and the aggregated report (from coverage module). --> - ${maven.multiModuleProjectDirectory}/coverage/target/site/jacoco-aggregate/jacoco.xml + ${project.build.directory}/site/jacoco/jacoco.xml,${maven.multiModuleProjectDirectory}/coverage/target/site/jacoco-aggregate/jacoco.xml components/camel-jackson3/**,components/camel-jackson3xml/**,components/camel-test/camel-test-junit6/**