SonarCloud PR Analysis Shows “0 New Lines” Despite Code Changes in Monorepo

Context

I’m working in a Python monorepo with multiple modules. I want SonarCloud to analyze only changed modules in PRs, comment on PRs, and flag new issues. My setup uses GitHub Actions with a matrix strategy to detect changed modules and run SonarCloud scans. The relevant module is rest_api, which has its own sonar-project.properties file.

Workflow Trigger

on:
  pull_request:
    branches: [main]
    types: [opened, reopened, synchronize, labeled]
  push:
    branches: [main]
    tags:
      - "v*.*.*"

SonarCloud Scan Step

- name: SonarQube Scan
  uses: SonarSource/sonarqube-scan-action@v7
  env:
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  with:
    projectBaseDir: ${{ matrix.module }}/
    args: >
      -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
      -Dsonar.pullrequest.branch=${{ github.head_ref }}
      -Dsonar.pullrequest.base=${{ github.base_ref }}

Config in sonar-project.properties

sonar.projectKey=greenshift-app_managementportal_v2
sonar.organization=greenshift-app
sonar.sources=rest_api_server,optscale_console,optscale_metrics,google_calendar_client
sonar.exclusions=**/tests/**,**/__pycache__/**,**/migrations/**,**/*.pyc,**/mock_data/**,**/*.tar.xz

Issue

Even after making some temporary changes to .py files, SonarCloud reports “0 new lines” in the PR analysis and does not flag new issues:

You can see that the workflow is triggered but it recognise 0 issues, even if I added some very ugly and bad-practice code. Here is what I see in sonarQube Cloud center:

I confirm that it is on the correct branch, and there is even the latest commit on this branch (see the red circle). However, it shows “0 New Lines”

Raw Logs

SonarCloud Scan Log

15:12:46.738 INFO  SCM writing changed lines
15:12:46.758 INFO  SCM writing changed lines (done) | time=21ms
15:12:48.225 INFO  ANALYSIS SUCCESSFUL, you can find the results at: .../dashboard?id=greenshift-app_managementportal_v2&pullRequest=501
...
15:31:10.854 INFO  The Python analyzer was able to leverage cached data from previous analyses for 0 out of 111 files. These files were not parsed.

What I’ve Tried

  • Ensured correct branch checkout (not merge commit)

  • Used commit SHAs for diff detection

  • Updated to recommended SonarCloud action

  • Verified sonar.sources and exclusions

  • Confirmed changed files are detected in the workflow

Question

Why does SonarCloud report “0 new lines” in PR analysis, even though files are changed and detected in the workflow? What else could cause SonarCloud to miss new lines/issues in a PR?

  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
  • Steps to reproduce
  • Potential workaround

Indeed! The temporary testing code I added is so ugly and I really expect Sonarqube to find it but it does not.

Hi,

Your second screenshot shows “Las analysis had a warning”. What is that warning?

And can you share the full analysis log?

Tangentially, this shouldn’t be needed:

That should be picked up automatically from your environment.

 
Ann

Thanks! The warning is just about a python version:

```
**
Warnings in last analysis**

Your code is analyzed as compatible with all Python 3 versions by default. You can get a more precise analysis by setting the exact Python version in your configuration via the parameter “sonar.python.version”

Hi,

Thanks for the warning.

 
Thx,
Ann

Hi Ann, this is the complete log of the sonarqube review. Thanks!

2_SonarQube Review (rest_api).txt (41.1 KB)

Hi,

Thanks for the log. There are some odd notes here, but no smoking gun.

I see you’re manually specifying some parameters that should normally be picked up out of the environment:

-Dsonar.pullrequest.key=501 -Dsonar.pullrequest.branch=GN-867-set-up-sonar-qube-for-rest-api-module -Dsonar.pullrequest.base=main

Could you leave those off and add -Dsonar.verbose=true to your analysis command line and give me that log, please?

 
Thx,
Ann