Repository navigation
Wire JaCoCo test coverage from codecov job into SonarCloud analysis - #19376
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wire the merged JaCoCo XML coverage report produced by the
codecovjob into thesonarjob in.github/workflows/sonar-codecov.ymlso SonarCloud reports actual test coverage on PRs and branch scans instead of always reporting0.0% Coverage on New Code.Root Causes Found
codecovandsonarran independently in parallel;sonarranmvn -B verify sonar:sonar ... -DskipTestswithout receiving any JaCoCo XML report.pom.xmlconfigured<sonar.coverage.jacoco.xmlReportPaths>target/jacoco-merged-reports/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>, which does not exist in submodules analyzed duringsonar(causingNo coverage report can be foundwarnings in every module).apache_iotdbSonarCloud project settings currently configuresonar.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.code-coverage/copy-code-coverage-sources.shonly copied../iotdb-core/*/target/and../iotdb-client/*/target/, missingiotdb-api/*,iotdb-core/metrics/*,library-udf, andexternal-service-impl/{mqtt,rest}.Changes
.github/workflows/sonar-codecov.yml:codecov, uploadcode-coverage/target/jacoco-merged-reports/jacoco.xmlas artifactjacoco-merged-report(actions/upload-artifact@v6,retention-days: 1,if-no-files-found: warn) right afterTestsucceeds.sonardepend oncodecov(needs: [codecov]) withif: ${{ !cancelled() && ((github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'apache/iotdb') || github.event_name == 'push') }}:codecovfails (e.g., due to a flaky UT),sonarstill runs static analysis cleanly without coverage instead of failing on artifact download.jacoco-merged-report(actions/download-artifact@v7,continue-on-error: true) only whensteps.sonar-scope.outputs.run_sonar == 'true' && needs.codecov.result == 'success'into${{ runner.temp }}/sonar-coverage(outside${GITHUB_WORKSPACE}so Mavenverify,apache-rat:check, andxml-formatnever scan or modify the downloaded report).-Dsonar.coverage.jacoco.xmlReportPaths=${JACOCO_REPORT}tomvn -B verify sonar:sonarwhen${{ runner.temp }}/sonar-coverage/jacoco.xmlexists, and log a graceful fallback otherwise.pom.xml:<sonar.coverage.exclusions>**/generated-sources/**</sonar.coverage.exclusions>to override the server-side*, **/*coverage exclusion while still excluding generated sources.<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.xmlso 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:.execfiles andtarget/classes(only from modules containingsrc/main/java, intentionally skipping generated-only modules such asexternal-service-impl/rest-openapiwhose stub**/impl/**classes would otherwise collide withexternal-service-impl/rest) acrossiotdb-api/*,iotdb-client/*,iotdb-core/*,iotdb-core/metrics/*,library-udf, andexternal-service-impl/*.set -euo pipefail,shopt -s nullglob, andcd "$(dirname "$0")"for safe execution.Concrete Before-and-After Behavior
apache/iotdbPR with Java changes (e.g., Fix race dropping failure cause in DriverContext.failed before local sink abort #19365, Bound MPP sink notifications by the query deadline #19344) andmasterpush,sonarran in parallel withcodecov, loggedExcluded sources for coverage: *, **/*andNo coverage report can be found with sonar.coverage.jacoco.xmlReportPaths='target/jacoco-merged-reports/jacoco.xml'for every module, and SonarCloud displayed0.0% Coverage on New Code(new_lines_to_cover = 0).codecovproduces a complete cross-modulecode-coverage/target/jacoco-merged-reports/jacoco.xml(coveringiotdb-api/*,iotdb-client/*,iotdb-core/*,iotdb-core/metrics/*,library-udf, andexternal-service-impl/{mqtt,rest}) and uploads it as a 1-day artifact beforesonarstarts.sonardownloads the report to${{ runner.temp }}/sonar-coverage/jacoco.xml, passes it via-Dsonar.coverage.jacoco.xmlReportPaths, and overridessonar.coverage.exclusionsto**/generated-sources/**, enabling SonarCloud to report real line/branch coverage on PRs and branch scans.codecovfails,sonarskips artifact download and still completes static analysis normally; if a PR has no analyzable Java changes (run_sonar=false),sonarskips both download and scan.Validation
.github/workflows/sonar-codecov.ymlviapython3yaml.safe_loadand verified jobneeds,if, and step structure.bash -n code-coverage/copy-code-coverage-sources.shand executed end-to-endmvn -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 mergedjacoco.xmlincludesorg/apache/iotdb/udf/api,org/apache/iotdb/metrics, and cross-moduleorg/apache/iotdb/isessioncoverage.pom.xmlformatting and license headers withmvn -B xml-format:xml-check -N -DindentSize=4 -Dincludes=pom.xmlandmvn -B apache-rat:check -N.${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..github/scripts/check-sonar-pr-diff.py --base-ref refs/remotes/origin/master --head-ref HEAD.