This is an automated email from the ASF dual-hosted git repository. JackieTien97 pushed a commit to branch ty/wire-jacoco-to-sonar in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a3619e21b956e6f83094ed5ac996838c27e1991c Author: JackieTien97 <[email protected]> AuthorDate: Tue Nov 24 10:16:21 2026 +0800 Wire JaCoCo test coverage from codecov job into SonarCloud analysis --- .github/workflows/sonar-codecov.yml | 38 ++++++++++++++++++++++++----- code-coverage/copy-code-coverage-sources.sh | 35 ++++++++++++++------------ pom.xml | 3 ++- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/.github/workflows/sonar-codecov.yml b/.github/workflows/sonar-codecov.yml index 92bf0d61102..24f8709fd39 100644 --- a/.github/workflows/sonar-codecov.yml +++ b/.github/workflows/sonar-codecov.yml @@ -60,6 +60,13 @@ jobs: run: | mvn -B -P with-code-coverage clean package -pl distribution,iotdb-client/cli,iotdb-client/session,iotdb-client/jdbc -am -Dtest.port.closed=true -DforkCount=4 mvn -B -P with-code-coverage post-integration-test -pl code-coverage + - name: Upload JaCoCo report for SonarCloud + uses: actions/upload-artifact@v6 + with: + name: jacoco-merged-report + path: code-coverage/target/jacoco-merged-reports/jacoco.xml + retention-days: 1 + if-no-files-found: warn - name: Upload coverage reports to codecov uses: codecov/codecov-action@v5 with: @@ -67,8 +74,9 @@ jobs: files: ./code-coverage/target/jacoco-merged-reports/jacoco.xml sonar: + needs: [codecov] runs-on: ubuntu-latest - if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'apache/iotdb') || github.event_name == 'push' + if: ${{ !cancelled() && ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'apache/iotdb') || github.event_name == 'push') }} env: MAVEN_OPTS: -Xms2g -Xmx8g -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3 steps: @@ -96,6 +104,13 @@ jobs: --base-ref "refs/remotes/origin/${BASE_REF}" \ --head-ref HEAD \ --github-output "${GITHUB_OUTPUT}" + - name: Download JaCoCo report from codecov job + if: steps.sonar-scope.outputs.run_sonar == 'true' && needs.codecov.result == 'success' + continue-on-error: true + uses: actions/download-artifact@v7 + with: + name: jacoco-merged-report + path: ${{ runner.temp }}/sonar-coverage - name: Set up JDK 21 if: steps.sonar-scope.outputs.run_sonar == 'true' uses: actions/setup-java@v5 @@ -124,10 +139,21 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} + JACOCO_REPORT: ${{ runner.temp }}/sonar-coverage/jacoco.xml run: | + set -euo pipefail + SONAR_ARGS=( + -Dsonar.organization=apache + -Dsonar.projectKey=apache_iotdb + -Dsonar.host.url=https://sonarcloud.io + -Dsonar.token="${SONAR_TOKEN}" + ) + if [ -f "${JACOCO_REPORT}" ]; then + echo "Using JaCoCo coverage report: ${JACOCO_REPORT}" + SONAR_ARGS+=("-Dsonar.coverage.jacoco.xmlReportPaths=${JACOCO_REPORT}") + else + echo "JaCoCo coverage report not found at ${JACOCO_REPORT}; running SonarCloud without coverage." + fi mvn -B verify sonar:sonar \ - -Dsonar.organization=apache \ - -Dsonar.projectKey=apache_iotdb \ - -Dsonar.host.url=https://sonarcloud.io \ - -Dsonar.token="${SONAR_TOKEN}" \ - -DskipTests -pl '!distribution' -am + "${SONAR_ARGS[@]}" \ + -DskipTests -pl '!distribution' -am diff --git a/code-coverage/copy-code-coverage-sources.sh b/code-coverage/copy-code-coverage-sources.sh index ea98fa27063..4db3569b6e8 100755 --- a/code-coverage/copy-code-coverage-sources.sh +++ b/code-coverage/copy-code-coverage-sources.sh @@ -18,24 +18,27 @@ # under the License. # -for file in ../iotdb-core/*/target/*.exec -do - cp $file ./target/ -done +set -euo pipefail +shopt -s nullglob -for file in ../iotdb-core/*/target/classes -do - echo "copy from" ${file} - cp -r $file ./target/ -done +cd "$(dirname "$0")" +mkdir -p ./target/classes -for file in ../iotdb-client/*/target/*.exec +for module in \ + ../iotdb-api/* \ + ../iotdb-client/* \ + ../iotdb-core/* \ + ../iotdb-core/metrics/* \ + ../library-udf \ + ../external-service-impl/* do - cp $file ./target/ -done + for file in "$module"/target/*.exec + do + cp "$file" ./target/ + done -for file in ../iotdb-client/*/target/classes -do - echo "copy from" ${file} - cp -r $file ./target/ + if [ -d "$module/src/main/java" ] && [ -d "$module/target/classes" ]; then + echo "copy from ${module}/target/classes" + cp -r "$module/target/classes/." ./target/classes/ + fi done diff --git a/pom.xml b/pom.xml index 425530778fe..c7b66dddf58 100644 --- a/pom.xml +++ b/pom.xml @@ -124,7 +124,8 @@ <reflections.version>0.10.2</reflections.version> <slf4j.version>2.0.9</slf4j.version> <snappy-java.version>1.1.10.9</snappy-java.version> - <sonar.coverage.jacoco.xmlReportPaths>target/jacoco-merged-reports/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths> + <sonar.coverage.exclusions>**/generated-sources/**</sonar.coverage.exclusions> + <sonar.coverage.jacoco.xmlReportPaths>${maven.multiModuleProjectDirectory}/code-coverage/target/jacoco-merged-reports/jacoco.xml,target/jacoco-merged-reports/jacoco.xml,target/jacoco-unit-reports/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths> <!-- Exclude all generated code --> <sonar.exclusions>**/generated-sources</sonar.exclusions> <sonar.test.exclusions>**/test/**</sonar.test.exclusions>
