I am trying to setup SonarQube for a project hosted on Github. The settings offered in the SonarQube UI are good, despite the fact that the project uses the Objective-C programming language. The Github Action I am using is
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud 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 }}
and it fails with
ERROR: Error during SonarScanner execution
java.lang.UnsupportedOperationException:
The only way to get an accurate analysis of C/C++/Objective-C files is by using the
SonarSource build-wrapper and setting the property "sonar.cfamily.build-wrapper-output"
or by using Clang Compilation Database and setting the property
"sonar.cfamily.compile-commands". None of these two options were specified.
Is there some Github Action that will run the SonarSource build-wrapper, or what would be the best next step?
So I extended my workflow as follows. There are a few caveats:
there is a nice Github Action 'SonarSource/sonarcloud-github-c-cpp@v1'. Is this sufficient to analyze Objective-C projects?
Git checkout will remove unnecessary directories. Hence you must install SonarQube AFTER having checkout out your source
The build wrapper just monitors the actual build, so you still have to run the Sonar Scanner afterwards
Here is the resulting code:
jobs:
SonarQube:
runs-on: ubuntu-latest
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
submodules: recursive
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v1
- name: Run build-wrapper
run: |
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make -f Makefile pkg-posix-nightly HOST_ARCH=$(uname -m)
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} # Put the name of your token here
run: |
sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"