Skip to content

Wire JaCoCo test coverage from codecov job into SonarCloud analysis - #19376

Merged
JackieTien97 merged 1 commit into
masterfrom
ty/wire-jacoco-to-sonar
Nov 24, 2026
Merged

JackieTien97 merged 1 commit into
masterfrom
ty/wire-jacoco-to-sonar

Conversation

@JackieTien97

Copy link
Copy Markdown
Contributor

Summary

Wire the merged JaCoCo XML coverage report produced by the codecov job into the sonar job in .github/workflows/sonar-codecov.yml so SonarCloud reports actual test coverage on PRs and branch scans instead of always reporting 0.0% Coverage on New Code.

Root Causes Found

  1. Disconnected CI jobs: codecov and sonar ran independently in parallel; sonar ran mvn -B verify sonar:sonar ... -DskipTests without receiving any JaCoCo XML report.
  2. Unresolvable report path in submodules: pom.xml configured <sonar.coverage.jacoco.xmlReportPaths>target/jacoco-merged-reports/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>, which does not exist in submodules analyzed during sonar (causing No coverage report can be found warnings in every module).
  3. SonarCloud server-side coverage exclusion: The apache_iotdb SonarCloud project settings currently configure sonar.coverage.exclusions = *, **/* (Excluded sources for coverage: *, **/* in every scan log), causing SonarCloud to exclude 100% of files from coverage calculation (new_lines_to_cover = 0) unless overridden by scanner/POM properties.
  4. Incomplete merged report collection: code-coverage/copy-code-coverage-sources.sh only copied ../iotdb-core/*/target/ and ../iotdb-client/*/target/, missing iotdb-api/*, iotdb-core/metrics/*, library-udf, and external-service-impl/{mqtt,rest}.

Changes

  • .github/workflows/sonar-codecov.yml:
    • In codecov, upload code-coverage/target/jacoco-merged-reports/jacoco.xml as artifact jacoco-merged-report (actions/upload-artifact@v6, retention-days: 1, if-no-files-found: warn) right after Test succeeds.
    • Make sonar depend on codecov (needs: [codecov]) with if: ${{ !cancelled() && ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'apache/iotdb') || github.event_name == 'push') }}:
      • Preserves exact repo/event gating and avoids running when cancelled.
      • If codecov fails (e.g., due to a flaky UT), sonar still runs static analysis cleanly without coverage instead of failing on artifact download.
    • Download jacoco-merged-report (actions/download-artifact@v7, continue-on-error: true) only when steps.sonar-scope.outputs.run_sonar == 'true' && needs.codecov.result == 'success' into ${{ runner.temp }}/sonar-coverage (outside ${GITHUB_WORKSPACE} so Maven verify, apache-rat:check, and xml-format never scan or modify the downloaded report).
    • Pass -Dsonar.coverage.jacoco.xmlReportPaths=${JACOCO_REPORT} to mvn -B verify sonar:sonar when ${{ runner.temp }}/sonar-coverage/jacoco.xml exists, and log a graceful fallback otherwise.
  • pom.xml:
    • Add <sonar.coverage.exclusions>**/generated-sources/**</sonar.coverage.exclusions> to override the server-side *, **/* coverage exclusion while still excluding generated sources.
    • Update <sonar.coverage.jacoco.xmlReportPaths> to ${maven.multiModuleProjectDirectory}/code-coverage/target/jacoco-merged-reports/jacoco.xml,target/jacoco-merged-reports/jacoco.xml,target/jacoco-unit-reports/jacoco.xml so multi-module local/reactor scans resolve both the merged report and per-module reports at any nesting depth.
  • code-coverage/copy-code-coverage-sources.sh:
    • Collect .exec files and target/classes (only from modules containing src/main/java, intentionally skipping generated-only modules such as external-service-impl/rest-openapi whose stub **/impl/** classes would otherwise collide with external-service-impl/rest) across iotdb-api/*, iotdb-client/*, iotdb-core/*, iotdb-core/metrics/*, library-udf, and external-service-impl/*.
    • Use set -euo pipefail, shopt -s nullglob, and cd "$(dirname "$0")" for safe execution.

Concrete Before-and-After Behavior

  • Before:
  • After:
    • codecov produces a complete cross-module code-coverage/target/jacoco-merged-reports/jacoco.xml (covering iotdb-api/*, iotdb-client/*, iotdb-core/*, iotdb-core/metrics/*, library-udf, and external-service-impl/{mqtt,rest}) and uploads it as a 1-day artifact before sonar starts.
    • sonar downloads the report to ${{ runner.temp }}/sonar-coverage/jacoco.xml, passes it via -Dsonar.coverage.jacoco.xmlReportPaths, and overrides sonar.coverage.exclusions to **/generated-sources/**, enabling SonarCloud to report real line/branch coverage on PRs and branch scans.
    • If codecov fails, sonar skips artifact download and still completes static analysis normally; if a PR has no analyzable Java changes (run_sonar=false), sonar skips both download and scan.

Validation

  • Validated .github/workflows/sonar-codecov.yml via python3 yaml.safe_load and verified job needs, if, and step structure.
  • Verified bash -n code-coverage/copy-code-coverage-sources.sh and executed end-to-end mvn -B -P with-code-coverage test -pl iotdb-api/udf-api,iotdb-core/metrics/interface -am -Dtest.port.closed=true && mvn -B -P with-code-coverage post-integration-test -pl code-coverage, confirming the merged jacoco.xml includes org/apache/iotdb/udf/api, org/apache/iotdb/metrics, and cross-module org/apache/iotdb/isession coverage.
  • Validated pom.xml formatting and license headers with mvn -B xml-format:xml-check -N -DindentSize=4 -Dincludes=pom.xml and mvn -B apache-rat:check -N.
  • Verified ${maven.multiModuleProjectDirectory} interpolation in both root (mvn help:effective-pom -N) and nested submodule (mvn help:effective-pom -pl iotdb-core/metrics/core) effective POMs.
  • Verified .github/scripts/check-sonar-pr-diff.py --base-ref refs/remotes/origin/master --head-ref HEAD.

@JackieTien97
JackieTien97 merged commit 835a7bb into master Nov 24, 2026
44 of 48 checks passed
@JackieTien97
JackieTien97 deleted the ty/wire-jacoco-to-sonar branch November 24, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant