Code coverage not calculated with Swift and Github Actions

  • ALM used (GitHub)
  • CI system used (Github Actions)
  • Scanner command used when applicable:
 uses: SonarSource/sonarcloud-github-action@master
 env:
     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
     SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

sonar-project.properties file:
sonar.projectKey=xxx-ios

sonar.organization=xxx-ios-app
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
sonar.objc.file.suffixes=-
sonar.coverageReportPaths=sonar-generic-coverage.xml
sonar.sources=.
sonar.exclusions=Tests/**
sonar.tests=Tests
sonar.test.inclusions=Tests/*.swift
sonar.verbose=true

  • Languages of the repository: Swift

  • Steps to reproduce:
    I have a github actions workflow job on a PR which executes the following to generate the code coverage report (uses xcode 13.2.1):
    xcodebuild test-without-building -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device" -enableCodeCoverage YES -resultBundlePath "CodeCoverage.xcresult"

Then the report is transformed using:
bash xcov-to-sonar-generic.sh CodeCoverage.xcresult > sonar-generic-coverage.xml

Since SonarScanner only runs on linux, and my xcodebuild runs on mac, I export the artifact for another github actions job:

uses: actions/upload-artifact@v2
with:
    name: code-coverage
    path: sonar-generic-coverage.xml

And in the following github actions job I execute the following:

  sonar:
    name: Run SonarCloud scan
    needs: build
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: Download code coverage 
        uses: actions/download-artifact@v2
        with:
          name: code-coverage
      - name: Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}  # Needed to get PR information, if any
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

However, I do not get the coverage in the scan analysis results, it stays at 0%. This is the log I get:

INFO: Sensor Generic Coverage Report
INFO: Parsing /github/workspace/sonar-generic-coverage.xml
INFO: Imported coverage data for 0 files
INFO: Coverage data ignored for 159 unknown files, including:
/Users/runner/work/ios/ios/qcast/Cells/Auth/AuthTextFieldTableCell.swift

My folder structure is as follows:

rootDir:
→ qcast
→ qcast.xcodeproj
→ qcast.xcworkspace
→ Tests

Hey there.

You’ll usually run into some trouble trying to upload a coverage report generated on another machine. You might be interested in what this user did here (using macos-latest and instead of using the GitHub action, executing the scanner manually).

At the same time, I don’t know if this is really how we want this use-case to be handled, so I’ll ping internally.

I’ve seen this slather discussion, but didn’t like the manual approach of using a bunch of tools explicitly.
I guess I’ll give it a try then, given that there is no workaround.

However, I am hoping for a cleaner fix, by using the sonar-scanner github actions instead.

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