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/**