Skip to content

Commit 2004324

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 3924b3e commit 2004324

3 files changed

Lines changed: 120 additions & 2 deletions

File tree

.github/workflows/sonar-build.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
name: SonarBuild
19+
20+
on:
21+
pull_request:
22+
branches:
23+
- main
24+
paths-ignore:
25+
- README.md
26+
- SECURITY.md
27+
- Jenkinsfile
28+
- Jenkinsfile.*
29+
- NOTICE.txt
30+
31+
permissions:
32+
contents: read
33+
34+
concurrency:
35+
group: sonar-pr-${{ github.event.pull_request.head.repo.full_name }}-${{ github.event.pull_request.head.ref }}
36+
cancel-in-progress: true
37+
38+
jobs:
39+
build:
40+
if: github.repository == 'apache/camel'
41+
name: Build for Sonar Analysis
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
45+
with:
46+
persist-credentials: false
47+
48+
- id: install-packages
49+
uses: ./.github/actions/install-packages
50+
51+
- name: Set up JDK 21
52+
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
53+
with:
54+
distribution: 'temurin'
55+
java-version: '21'
56+
cache: 'maven'
57+
58+
- name: Build with Maven
59+
run: ./mvnw install -B -Dquickly
60+
61+
# Run core tests with JaCoCo and generate aggregated coverage 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
65+
run: >
66+
./mvnw verify -B -Dcoverage
67+
-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
68+
-Dmaven.test.failure.ignore=true
69+
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+
- name: Prepare compiled classes artifact
83+
shell: bash
84+
run: find . -name "target" -type d | tar -czf target.tar.gz -T -
85+
86+
- name: Upload compiled classes artifact
87+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
88+
id: target-upload
89+
with:
90+
name: sonar-target
91+
path: target.tar.gz
92+
if-no-files-found: error
93+
retention-days: 1
94+
95+
- name: Prepare pull request metadata
96+
shell: bash
97+
run: |
98+
echo "${{ github.event.pull_request.number }}" > pr-event.txt
99+
echo "${{ github.event.pull_request.head.ref }}" >> pr-event.txt
100+
echo "${{ github.event.pull_request.base.ref }}" >> pr-event.txt
101+
echo "${{ github.event.pull_request.head.sha }}" >> pr-event.txt
102+
echo "${{ steps.target-upload.outputs.artifact-id }}" >> pr-event.txt
103+
104+
- name: Upload pull request metadata
105+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
106+
with:
107+
name: sonar-pr-event
108+
path: pr-event.txt
109+
if-no-files-found: error
110+
retention-days: 1

parent/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4490,6 +4490,13 @@
44904490
</excludes>
44914491
</configuration>
44924492
</execution>
4493+
<execution>
4494+
<id>report</id>
4495+
<phase>verify</phase>
4496+
<goals>
4497+
<goal>report</goal>
4498+
</goals>
4499+
</execution>
44934500
</executions>
44944501
</plugin>
44954502
<plugin>

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@
121121
<project.build.outputTimestamp>2026-02-17T16:11:10Z</project.build.outputTimestamp>
122122

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

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

0 commit comments

Comments
 (0)