iosswiftcode-coveragesonarcloudbitrise

Sonarcloud code coverage for pull request with bitrise


I have iOS project and for main branch works fine but for pull request I see 0 New Lines. I have this bitrise step for pull request:

$BITRISE_SOURCE_DIR/xccov-to-sonarqube-generic.sh $BITRISE_XCRESULT_PATH > Coverage.xml

sonar-scanner -Dsonar.projectKey={porjectKey} \
-Dsonar.organization={projectOrgatization} \
-Dsonar.pullrequest.base=$BITRISEIO_GIT_BRANCH_DEST \
-Dsonar.pullrequest.branch=$BITRISE_GIT_BRANCH \
-Dsonar.pullrequest.key=$PULL_REQUEST_ID \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.coverageReportPaths=Coverage.xml \
-Dsonar.language=swift \
-Dsonar.sources=App,ImageShare \
-Dsonar.tests=Tests \
-Dsonar.c.file.suffixes=- \
-Dsonar.cpp.file.suffixes=- \
-Dsonar.objc.file.suffixes=- \

sonarcloud screenshot

Here is logs from sonar-scanner:

INFO: Scanner configuration file: /opt/homebrew/Cellar/sonar-scanner/5.0.1.3006/libexec/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 5.0.1.3006
INFO: Java 20.0.2 Homebrew (64-bit)
INFO: Mac OS X 13.5 aarch64
INFO: User cache: /Users/vagrant/.sonar/cache
INFO: Analyzing on SonarCloud
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=268ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /Users/vagrant/.sonar/cache
INFO: Loading required plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=586ms
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=819ms
INFO: Found an active CI vendor: 'Bitrise'
INFO: Load project settings for component key: 'ProjectKey'
INFO: Load project settings for component key: 'ProjectKey' (done) | time=216ms
INFO: Process project properties
INFO: Project key: ProjectKey
INFO: Base dir: /Users/vagrant/git
INFO: Working dir: /Users/vagrant/git/.scannerwork
INFO: Load project branches
INFO: Load project branches (done) | time=235ms
INFO: Check ALM binding of project 'ProjectKey'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'ProjectKey' (done) | time=231ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=553ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=1ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=284ms
INFO: Load active rules
INFO: Load active rules (done) | time=12355ms
INFO: Organization key: OrganizationKey
INFO: Branch name: test-coverage, type: short-lived
INFO: Preprocessing files...
INFO: 2 languages detected in 1341 preprocessed files
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 574 files ignored because of scm ignore settings
INFO: Loading plugins for detected languages
INFO: Load/download plugins
INFO: Load/download plugins (done) | time=32ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=1005ms
INFO: SCM collecting changed files in the branch
INFO: SCM collecting changed files in the branch (done) | time=226ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/build-wrapper-dump.json
INFO:   Excluded sources for duplication: Tests
INFO: 1341 files indexed
INFO: Quality profile for json: Sonar way
INFO: Quality profile for swift: Sonar way
INFO: ------------- Run sensors on module ProjectKey
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=205ms
INFO: Sensor cache enabled
INFO: Load sensor cache
INFO: Load sensor cache (19 KB) | time=1394ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
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
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor IaC CloudFormation Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC CloudFormation Sensor [iac] (done) | time=87ms
INFO: Sensor IaC AzureResourceManager Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC AzureResourceManager Sensor [iac] (done) | time=61ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: 954 source files to be analyzed
INFO: 954/954 source files have been analyzed
INFO: Sensor TextAndSecretsSensor [text] (done) | time=3058ms
INFO: Sensor Swift Code Quality and Security [swift]
INFO: 590 source files to be analyzed
INFO: 590/590 source files have been analyzed
INFO: Sensor Swift Code Quality and Security [swift] (done) | time=8211ms
INFO: Sensor IaC Docker Sensor [iac]
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Sensor IaC Docker Sensor [iac] (done) | time=24ms
INFO: Sensor Generic Coverage Report
INFO: Parsing /Users/vagrant/git/cov.xml
INFO: Imported coverage data for 494 files
INFO: Sensor Generic Coverage Report (done) | time=265ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=11ms
INFO: CPD Executor 127 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 463 files
INFO: CPD Executor CPD calculation finished (done) | time=70ms
INFO: SCM writing changed lines
INFO: SCM writing changed lines (done) | time=15ms
INFO: Analysis report generated in 242ms, dir size=734 KB
INFO: Analysis report compressed in 456ms, zip size=613 KB
INFO: Analysis report uploaded in 1437ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=ProjectKey&branch=test-coverage&resolved=false
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at https://sonarcloud.io/api/ce/task?id=taskId
INFO: Analysis total time: 36.084 s

When I click this link https://sonarcloud.io/api/ce/task?id=taskId, I receive:

{"errors":[{"msg":"Project doesn\u0027t exist"}]}

What I'm doing wrong?


Solution

  • I found the solution here:

    1. “git-clone” step was by default merging the src branch head commit into master and I could parameterize it and skip that step.
    2. When I disabled the merge on the “git-clone” step, the step did not even pull down the master. So I added an additional script step to pull down the “master” branch after the “git-clone” step.

    I have additional command just before sonar-scanner:

    git pull origin $BITRISEIO_GIT_BRANCH_DEST