Main Branch is Not Updating in SonarCloud for Mobile Swift Application When Running After Merge

Our team uses feature branches to track work that gets merged to our Main Branch develop when approved. Every PR in Github triggers CircleCI to kick off a custom fastlane script that analyzes the code via sonar cloud for issues and coverage. This works well and updates in SonarCloud as well as in the Github PR. Every evening we also have a trigger in CircleCI to test and deploy the app from our Main Branch develop that runs the same tests and sonar script. However when this runs this is not updating the Main Branch analysis details in Sonar Cloud. It has updated before, 15 days ago, but we have had many merges into develop since then with deployments daily.

What exactly triggers the Main Branch to update in SonarCloud? Is some setup or order with our workflows not triggering this to happen when we expect?

ALM used: GitHub
CI system used: Circle CI
Scanner command used when applicable: Fastlane sonar action (orb for mac machines is not supported)
Languages of the repository: Swift

Sonar Logs from our latest CircleCI Deployment job:

01:54:25]: -------------------
[01:54:25]: --- Step: sonar ---
[01:54:25]: -------------------
[01:54:25]: ▸ INFO: Scanner configuration file: /opt/homebrew/Cellar/sonar-scanner/5.0.1.3006/libexec/conf/sonar-scanner.properties
[01:54:25]: ▸ INFO: Project root configuration file: /Users/distiller/project/sonar-project.properties
[01:54:25]: ▸ INFO: SonarScanner 5.0.1.3006
[01:54:25]: ▸ INFO: Java 21.0.2 Homebrew (64-bit)
[01:54:25]: ▸ INFO: Mac OS X 14.3.1 aarch64
[01:54:25]: ▸ INFO: User cache: /Users/distiller/.sonar/cache
[01:54:28]: ▸ INFO: Analyzing on SonarCloud
[01:54:28]: ▸ INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
[01:54:28]: ▸ INFO: Load global settings
[01:54:28]: ▸ INFO: Load global settings (done) | time=482ms
[01:54:28]: ▸ INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
[01:54:28]: ▸ INFO: User cache: /Users/distiller/.sonar/cache
[01:54:28]: ▸ INFO: Loading required plugins
[01:54:28]: ▸ INFO: Load plugins index
[01:54:29]: ▸ INFO: Load plugins index (done) | time=501ms
[01:54:29]: ▸ INFO: Load/download plugins
[01:54:30]: ▸ INFO: Load/download plugins (done) | time=777ms
[01:54:30]: ▸ INFO: Found an active CI vendor: 'CircleCI'
[01:54:30]: ▸ INFO: Load project settings for component key: 'syngenta-digital_mobile-ios-cropwise-financials'
[01:54:31]: ▸ INFO: Load project settings for component key: 'syngenta-digital_mobile-ios-cropwise-financials' (done) | time=455ms
[01:54:31]: ▸ INFO: Process project properties
[01:54:31]: ▸ INFO: Project key: syngenta-digital_mobile-ios-cropwise-financials
[01:54:31]: ▸ INFO: Base dir: /Users/distiller/project
[01:54:31]: ▸ INFO: Working dir: /Users/distiller/project/.scannerwork
[01:54:31]: ▸ INFO: Load project branches
[01:54:31]: ▸ INFO: Load project branches (done) | time=482ms
[01:54:31]: ▸ INFO: Check ALM binding of project 'syngenta-digital_mobile-ios-cropwise-financials'
[01:54:32]: ▸ INFO: Detected project binding: BOUND
[01:54:32]: ▸ INFO: Check ALM binding of project 'syngenta-digital_mobile-ios-cropwise-financials' (done) | time=451ms
[01:54:32]: ▸ INFO: Load project pull requests
[01:54:32]: ▸ INFO: Load project pull requests (done) | time=549ms
[01:54:32]: ▸ INFO: Load branch configuration
[01:54:32]: ▸ INFO: Auto-configuring pull request 2705
[01:54:34]: ▸ INFO: Load branch configuration (done) | time=1494ms
[01:54:34]: ▸ INFO: Load quality profiles
[01:54:34]: ▸ INFO: Load quality profiles (done) | time=539ms
[01:54:34]: ▸ INFO: Load active rules
[01:54:48]: ▸ INFO: Load active rules (done) | time=13937ms
[01:54:49]: ▸ INFO: Organization key: syngenta-digital
[01:54:49]: ▸ INFO: Pull request 2705 for merge into release/1.7.0 from develop
[01:54:49]: ▸ INFO: Preprocessing files...
[01:54:50]: ▸ INFO: 2 languages detected in 2708 preprocessed files
[01:54:50]: ▸ INFO: 0 files ignored because of inclusion/exclusion patterns
[01:54:50]: ▸ INFO: 0 files ignored because of scm ignore settings
[01:54:50]: ▸ INFO: Loading plugins for detected languages
[01:54:50]: ▸ INFO: Load/download plugins
[01:54:50]: ▸ INFO: Load/download plugins (done) | time=42ms
[01:54:50]: ▸ INFO: Load project repositories
[01:54:52]: ▸ INFO: Load project repositories (done) | time=1514ms
[01:54:52]: ▸ INFO: SCM collecting changed files in the branch
[01:54:52]: ▸ INFO: SCM collecting changed files in the branch (done) | time=349ms
[01:54:52]: ▸ INFO: Indexing files...
[01:54:52]: ▸ INFO: Project configuration:
[01:54:52]: ▸ INFO:   Excluded sources: **/build-wrapper-dump.json, Pods/**/*, DerivedData/**/*
[01:54:52]: ▸ INFO:   Excluded sources for coverage: Pods/**/*, DerivedData/**/*, **/*ViewController.swift, **/*View.swift, **/*ViewCell.swift, **/*LayoutExtending.swift, **/*Layout.swift, **/*UIView+Utilities.swift
[01:54:52]: ▸ INFO: 2708 files indexed
[01:54:52]: ▸ INFO: Quality profile for json: SonarQube Way
[01:54:52]: ▸ INFO: Quality profile for swift: Swift - Financials
[01:54:52]: ▸ INFO: ------------- Run sensors on module mobile-ios-cropwise-financials
[01:54:52]: ▸ INFO: Load metrics repository
[01:54:53]: ▸ INFO: Load metrics repository (done) | time=430ms
[01:54:53]: ▸ INFO: Sensor cache enabled
[01:54:53]: ▸ INFO: Load sensor cache
[01:54:53]: ▸ INFO: Load sensor cache (404) | time=513ms
[01:54:54]: ▸ INFO: Sensor JaCoCo XML Report Importer [jacoco]
[01:54:54]: ▸ INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[01:54:54]: ▸ INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
[01:54:54]: ▸ INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms
[01:54:54]: ▸ INFO: Sensor IaC CloudFormation Sensor [iac]
[01:54:54]: ▸ INFO: 0 source files to be analyzed
[01:54:54]: ▸ INFO: 0/0 source files have been analyzed
[01:54:54]: ▸ INFO: Sensor IaC CloudFormation Sensor [iac] (done) | time=147ms
[01:54:54]: ▸ INFO: Sensor IaC AzureResourceManager Sensor [iac]
[01:54:54]: ▸ INFO: Sensor IaC AzureResourceManager Sensor is restricted to changed files only
[01:54:54]: ▸ INFO: 0 source files to be analyzed
[01:54:54]: ▸ INFO: 0/0 source files have been analyzed
[01:54:54]: ▸ INFO: Sensor IaC AzureResourceManager Sensor [iac] (done) | time=64ms
[01:54:54]: ▸ INFO: Sensor Swift Code Quality and Security [swift]
[01:54:54]: ▸ INFO: Sensor Swift Code Quality and Security is restricted to changed files only
[01:54:54]: ▸ INFO: 227 source files to be analyzed
[01:55:04]: ▸ INFO: 227/227 source files have been analyzed
[01:55:04]: ▸ INFO: Sensor Swift Code Quality and Security [swift] (done) | time=10037ms
[01:55:04]: ▸ INFO: Sensor IaC Docker Sensor [iac]
[01:55:04]: ▸ INFO: Sensor IaC Docker Sensor is restricted to changed files only
[01:55:04]: ▸ INFO: 0 source files to be analyzed
[01:55:04]: ▸ INFO: 0/0 source files have been analyzed
[01:55:04]: ▸ INFO: Sensor IaC Docker Sensor [iac] (done) | time=27ms
[01:55:04]: ▸ INFO: Sensor Generic Coverage Report
[01:55:04]: ▸ INFO: Parsing /Users/distiller/project/sonarqube-generic-coverage.xml
[01:55:04]: ▸ INFO: Imported coverage data for 937 files
[01:55:04]: ▸ INFO: Coverage data ignored for 1 unknown files, including:
[01:55:04]: ▸ DerivedData/Build/Intermediates.noindex/CropwiseFinancials.build/Stage-iphonesimulator/CropwiseFinancials.build/DerivedSources/GeneratedAssetSymbols.swift
[01:55:04]: ▸ INFO: Sensor Generic Coverage Report (done) | time=164ms
[01:55:04]: ▸ INFO: Sensor TextAndSecretsSensor [text]
[01:55:04]: ▸ INFO: Sensor TextAndSecretsSensor is restricted to changed files only
[01:55:04]: ▸ INFO: Available processors: 4
[01:55:04]: ▸ INFO: Using 4 threads for analysis.
[01:55:04]: ▸ INFO: 398 source files to be analyzed
[01:55:05]: ▸ INFO: 398/398 source files have been analyzed
[01:55:05]: ▸ INFO: Sensor TextAndSecretsSensor [text] (done) | time=1308ms
[01:55:05]: ▸ INFO: ------------- Run sensors on project
[01:55:05]: ▸ INFO: Sensor Zero Coverage Sensor
[01:55:05]: ▸ INFO: Sensor Zero Coverage Sensor (done) | time=9ms
[01:55:05]: ▸ INFO: SCM Publisher SCM provider for this project is: git
[01:55:05]: ▸ INFO: SCM Publisher 398 source files to be analyzed
[01:55:10]: ▸ INFO: SCM Publisher 398/398 source files have been analyzed (done) | time=4192ms
[01:55:10]: ▸ INFO: CPD Executor 4 files had no CPD blocks
[01:55:10]: ▸ INFO: CPD Executor Calculating CPD for 223 files
[01:55:10]: ▸ INFO: CPD Executor CPD calculation finished (done) | time=86ms
[01:55:10]: ▸ INFO: SCM writing changed lines
[01:55:11]: ▸ WARN: File '/Users/distiller/project/CropwiseFinancials/Features/Dashboard/Models/SyncTask.swift' was detected as changed but without having changed lines
[01:55:11]: ▸ WARN: File '/Users/distiller/project/CropwiseFinancials/Features/Yield/NewYield/Models/YieldTemplate.swift' was detected as changed but without having changed lines
[01:55:11]: ▸ WARN: File '/Users/distiller/project/CropwiseFinancials/Utilities/Extensions/NSCollectionLayoutSection+Extensions.swift' was detected as changed but without having changed lines
[01:55:11]: ▸ WARN: File '/Users/distiller/project/CropwiseFinancials/Features/Properties/ViewControllers/PropertiesViewController.swift' was detected as changed but without having changed lines
[01:55:11]: ▸ WARN: File '/Users/distiller/project/CropwiseFinancials/Features/Dashboard/Models/SyncTaskViewModels.swift' was detected as changed but without having changed lines
[01:55:11]: ▸ WARN: File '/Users/distiller/project/CropwiseFinancialsTests/Features/Properties/Models/CropZoneInformationTests.swift' was detected as changed but without having changed lines
[01:55:11]: ▸ WARN: File '/Users/distiller/project/CropwiseFinancials/Features/Dashboard/ViewModel/DashboardSyncViewModel.swift' was detected as changed but without having changed lines
[01:55:11]: ▸ WARN: File '/Users/distiller/project/CropwiseFinancials/Features/Properties/ViewModel/CropZoneFullDetailsListViewModel.swift' was detected as changed but without having changed lines
[01:55:11]: ▸ INFO: SCM writing changed lines (done) | time=771ms
[01:55:11]: ▸ INFO: Analysis report generated in 1232ms, dir size=6 MB
[01:55:12]: ▸ INFO: Analysis report compressed in 881ms, zip size=2 MB
[01:55:15]: ▸ INFO: Analysis report uploaded in 3480ms
[01:55:15]: ▸ INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=syngenta-digital_mobile-ios-cropwise-financials&pullRequest=2705
[01:55:15]: ▸ INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[01:55:15]: ▸ INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AY8N0HIZAIzZ0IN-8mVJ
[01:55:16]: ▸ INFO: Analysis total time: 45.532 s
[01:55:16]: ▸ INFO: ------------------------------------------------------------------------
[01:55:16]: ▸ INFO: EXECUTION SUCCESS
[01:55:16]: ▸ INFO: ------------------------------------------------------------------------
[01:55:16]: ▸ INFO: Total time: 50.460s
[01:55:16]: ▸ INFO: Final Memory: 68M/234M
[01:55:16]: ▸ INFO: ------------------------------------------------------------------------

Hi,

You should look for changes in your script.

To be clear, if you’re handling the analysis in your CI/scripts, then SonarCloud neither monitors your repo for changes nor initiates analysis (this is different if you’re using automatic analysis). So if analysis stopped happening, you need to see what changed in your scripts and/or CI.

 
HTH,
Ann

Yes, the analysis is indeed taking place. I confirmed with the log above which executed 2 days ago. But it seems like its always only being seen as a PR scan. I think I need some help in understanding when/how sonar knows to update scan results for Main Branch. We are running the scan “on our main branch” but are there other parameters that come into play here?

Per these lines:

[01:55:15]: ▸ INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=syngenta-digital_mobile-ios-cropwise-financials&pullRequest=2705
[01:55:15]: ▸ INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[01:55:15]: ▸ INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=AY8N0HIZAIzZ0IN-8mVJ

The processing and delivery of the report was successful per the report link. But I see the result url mentions &pullRequest=2705 Maybe thats a clue?

Hi,

Yes, that’s a clue. If you haven’t manually configured PR analysis parameters (not a best practice) then analysis is picking up whether it’s a branch (and which branch) or a PR analysis from the environment. Specifically, take a look here at your checkout.

 
HTH,
Ann

Thanks for your continued help. Funny enough without me making any config changes, our Main Branch was updated last night through our delivery pipeline :sweat_smile: Which I am happy about, but no closer into knowing why that happened, which gives me not much confidence it won’t happen again.

So to follow-up with you here, when you mention:

What exactly do you mean by this? Our analysis method in the sonar cloud platform is manual to properly capture code coverage. We do have a properties file with these set:

sonar.projectDescription=xxxxxxxxxxx
sonar.host.url=https://sonarcloud.io
sonar.organization==xxxxxxxxxxx
sonar.projectKey=xxxxxxxxxxx
sonar.projectName=mobile-ios-cropwise-financials
sonar.sources==xxxxxxxxxxx
sonar.tests=xxxxxxxxxxxTests
sonar.coverageReportPaths=sonarqube-generic-coverage.xml
sonar.exclusions=Pods/**/*,DerivedData/**/*
sonar.coverage.exclusions=Pods/**/*,DerivedData/**/*,**/*ViewController.swift,**/*View.swift,**/*ViewCell.swift,**/*LayoutExtending.swift,**/*Layout.swift,**/*UIView+Utilities.swift
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-

Second follow up question, I see now that in CircleCI logs it says:

[01:59:04]: ▸ INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=syngenta-digital_mobile-ios-cropwise-financials&branch=develop

The checkout logs look the same to me in both spots (see below). Checkout logic is managed by CircleCI so I can’t see exactly what calls they are making. So still a little confused why sonar chose pull request for one scenario and branch for the other when its the same pipeline script/code?

8 Days ago, did not update the head branch, included &pullrequest= in sonar logs

Cloning git repository
Checking out branch
Your branch is up to date with 'origin/develop'.
HEAD is now at 942f9a1ea Merge pull request #2718 from syngenta-digital/feature/cfi-3972-Storage-Location-List-empty-state

16 hours ago, did update the head branch, included &branch= in sonar logs

Cloning git repository
Checking out branch
Your branch is up to date with 'origin/develop'.
HEAD is now at a1e6d67af Merge pull request #2720 from syngenta-digital/feature/cfi-3999-Share-Basic-Info-Button
Cloning into '.'...

Hi,

Your properties look fine. What I meant by “manually configured PR analysis parameters” is you explicitly adding sonar.pullrequst.* parameters, which you’re not.

This is going to be about what was in your environment. Branch/PR values are picked up from the envvars populated by checkout.

TBH, it’s been a while since I delved into this, but was a PR open in your DevOps platform?

 
Ann

Well good news is now this is being run every evening like I expected it too. Maybe CircleCI changed something with their native checkout method but I think my issue is resolved.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.