Repository navigation
Scope PR SonarCloud analysis to PR diff and fix master OOM - #19355
JackieTien97 wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #19355 +/- ##
============================================
- Coverage 49.44% 49.43% -0.01%
Complexity 718 718
============================================
Files 5656 5656
Lines 418222 418222
Branches 55296 55296
============================================
- Hits 206769 206756 -13
- Misses 211453 211466 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
The workflow excludes dev/1.3 from its push triggers, making its scan condition unreachable and preventing SonarCloud baseline updates for that branch.
1 open issue
What changed in this PR
This PR aims to make SonarCloud analysis reflect PR changes more accurately, reduce unnecessary builds, and address heap exhaustion during full branch scans.
Changes:
- Fetch full Git history and resolve the PR base ref for changed-line detection.
- Select affected Maven modules for Java-source PRs and skip analysis when none qualify.
- Increase Maven heap, cache SonarCloud packages, and simplify the analysis command.
| File | Description |
|---|---|
.github/workflows/sonar-codecov.yml |
Integrates scan selection, full-history checkout, heap settings, and caching. |
.github/scripts/select-sonar-modules.py |
Maps changed main Java sources to eligible Maven modules and emits workflow outputs. |
Review effort: Balanced
| if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'apache/iotdb' || github.event_name == 'push' | ||
| if: >- | ||
| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'apache/iotdb') || | ||
| (github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev/1.3')) |
JackieTien97
left a comment
There was a problem hiding this comment.
-
Keep cross-module duplicates visible to the quality gate. With
-pl iotdb-api/pipe-api -am, Maven leavesudf-apiout of the scan. SonarCloud reports a 123-line duplicate between theBinary.javafiles in those two modules. A PR that copies code from one into the other can therefore pass the new-code duplication gate when only the destination module changes. Keep the skip for PRs with no analyzable Java changes, and use the target branch’s full analysis scope when a scan runs. Existing duplicate -
Check out the PR head for the Sonar job. The default checkout makes
--head-ref HEADpoint to GitHub’s synthetic merge commit. I reproduced a clean merge where the base moved a file from module A to B while the PR edited it in A. The selector chose A on the PR head and B on the merge commit. Set the checkout ref togithub.event.pull_request.head.shafor PRs andgithub.shafor pushes. Checkout configuration -
Refresh the baseline for release-branch PRs. PRs targeting
rc/*andrel/*still run Sonar, but the new push condition prevents those branches from establishing or refreshing their baseline. SonarCloud can then attribute issues already on the release branch to a later PR. Keep push analysis enabled for release branches that receive PR analysis. SonarCloud baseline requirements

Description
Currently, SonarCloud checks on pull requests frequently fail the Quality Gate with issues from unrelated files and untouched lines, while full
masterpush scans have been failing withOutOfMemoryError: Java heap space.Root Causes Observed
Shallow clone breaks Git SCM diff and changed-lines detection on PRs:
actions/checkout@v5in.github/workflows/sonar-codecov.ymlused the defaultfetch-depth: 1, without fetching the base branch ref. In PR runs (for example PR Bound MPP sink notifications by the query deadline #19344), the Sonar scanner logged:[WARNING] Could not find ref 'master' in refs/heads, refs/remotes, refs/remotes/upstream or refs/remotes/origin(in bothSCM collecting changed files in the branchandSCM writing changed lines)[WARNING] Shallow clone detected, no blame information will be provided.Without local Git merge-base and changed-line information, SonarCloud fell back to comparing against the last analyzed
mastersnapshot and treated entire differing files as "New Code".masterpush scans OOM with default JVM heap:MAVEN_OPTSin.github/workflows/sonar-codecov.ymldid not specify-Xmx, causing full-repomasterpush analysis to fail withjava.lang.OutOfMemoryError: Java heap spaceand leaving the SonarCloudmasterbaseline and server-side cache stale.Unnecessary scans on non-Java / example PRs and unused profiles:
The
sonarjob always ran-P with-integration-tests,with-code-coverageeven though-DskipTestsand-pl '!distribution,!integration-test'were passed, executing hundreds of skipped JaCoCo goals, scanningexample/*sample code, and running full builds even on test-only or docs/CI-only PRs.Changes
actions/checkout@v5reftogithub.event.pull_request.head.shaonpull_request(andgithub.shaonpush) withfetch-depth: 0, avoiding discrepancies introduced by GitHub's synthetic merge commit when the base branch moves files.refs/remotes/origin/${BASE_REF}is present so SonarCloud's native SCM changed-files, changed-lines, and blame analysis work accurately on PR diffs.exampleandintegration-testfrom Sonar analysis:<sonar.skip>true</sonar.skip>inexample/pom.xml(inherited by allexample/*submodules, avoiding Maven-plorphan-module errors and keepingarchitecture-testdependencies intact) and inintegration-test/pom.xml..github/scripts/check-sonar-pr-diff.pyinspects the PR three-dot diff (git diff --name-only --diff-filter=ACMR refs/remotes/origin/<base>...HEAD) and skips JDK setup, caches, and Maven/Sonar when no main Java source (src/main/java/**/*.java,src/main/i18n/en/**/*.java) in eligible default-reactor modules (excludingdistributionand any<sonar.skip>true</sonar.skip>subtree such asexample) changed.-pl '!distribution' -am) so cross-module duplications and analyses remain visible to the Quality Gate while SonarCloud's server-side cache skips unchanged files.push-triggered full scans for all branches inon.push.branches(master,rel/*,rc/*) so every target branch that receives PR analysis maintains an up-to-date SonarCloud baseline (codecovis unchanged).sonarjob: setMAVEN_OPTSwith-Xms2g -Xmx8g, drop unused-P with-integration-tests,with-code-coverage, and cache~/.sonar/cache.Before / After Examples
masterref, reported 143 files / 34,173 new lines / 6 unrelated bugs from othermastercommits, and failed the Quality Gate.github.event.pull_request.head.shawithfetch-depth: 0andrefs/remotes/origin/master, runs full-reactor analysis (-pl '!distribution' -am, skippingexample/*viasonar.skip) so cross-module duplicates remain visible, and lets SonarCloud evaluate only the PR diff's changed lines.example/**,integration-test/**, docs, or workflow files (e.g., this PR):~11 min).check-sonar-pr-diff.pyemitsrun_sonar=falseand skips Maven/Sonar in ~20s.pushtomaster,rel/*, orrc/*:java.lang.OutOfMemoryError: Java heap spaceunder default heap.-pl '!distribution' -am, skippingexample/*viasonar.skip) with-Xms2g -Xmx8gandfetch-depth: 0to keep the SonarCloud baseline and server-side cache up to date.This PR has:
Key changed/added files in this PR
.github/workflows/sonar-codecov.yml.github/scripts/check-sonar-pr-diff.pyexample/pom.xmlintegration-test/pom.xml