Hello,
I’m trying to switch from automatic analysis to manual analysis as we need code coverage of our Swift Project in sonar. I’m using Github Actions for this. I get no error messages and the workflow runs successful. My problem is, that the code coverage report is not uploaded to sonar and sonar always reports 0% code coverage.
It also seems that the scanner analyzes only the last commit, not the full pull request. When the last commit contains swift files to analyze it says:
Sensor Swift Code Quality and Security [swift]
14:48:58.932 INFO Sensor Swift Code Quality and Security is restricted to changed files only
14:48:59.125 INFO 2 source files to be analyzed
14:49:00.626 INFO 2/2 source files have been analyzed
but when I commit something, that doesn’t contain swift files. nothing get’s analyzed although the PR contains changed swift files:
Sensor Swift Code Quality and Security [swift] (done) | time=1695ms
08:50:53.877 INFO Sensor IaC Docker Sensor [iac]
08:50:53.877 INFO Sensor IaC Docker Sensor is restricted to changed files only
08:50:53.926 INFO 0 source files to be analyzed
08:50:53.927 INFO 0/0 source files have been analyzed
The workflow file is separated into multiple jobs:
- build_and_test: builds, tests and creates reports of the project. Runs on macOS and uses fast lane and puts all reports in a
reports/
folder
scan(
code_coverage: true,
derived_data_path: options[:derivedDataPath],
output_directory: options[:reportsPath]
)
slather(
cobertura_xml: true,
github: true,
scheme: "App",
build_directory: options[:derivedDataPath],
output_directory: options[:reportsPath],
proj: "./App.xcodeproj"
)
lizard(
source_folder: "./",
language: "swift",
export_type: "xml",
report_file: "reports/lizard-report.xml"
)
swiftlint(
output_file: "reports/swiftlint.json",
ignore_exit_status: true
)
The actual sonarqube job looks like the following:
sonarqube:
runs-on: ubuntu-latest
needs:
- build_and_test
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Reports
uses: actions/download-artifact@v4
with:
name: reports
path: reports
# See `sonar-project.properties` in project root folder for options
- name: 👀 SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v5
env:
SONAR_TOKEN: ${{ secrets.ORG_SONARCLOUD_TOKEN }}
Finally the sonar-project.properties
looks as follows:
sonar.projectKey=[PROJECT_KEY]
sonar.organization=[ORGANIZATION]
sonar.filesize.limit=30
# Reports
sonar.junit.reportsPath=reports/
sonar.junit.include=*.junit
sonar.swift.lizard.report=reports/lizard-report.xml
sonar.swift.coverage.reportPattern=reports/cobertura.xml
sonar.swift.swiftlint.report=reports/*swiftlint.json
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=.
What is wrong with the configuration, that it doesn’t report the code coverage correctly?
- Analyzing all swift files of the PR, not only last commit
- Report code coverage correctly to sonar?