SonarCloud anayzing Python code only but I ignored python code in sonar properties file.
ALM used (GitHub)
CI system used (GitHub actions
Languages of the repository C++,C and Python
SonarCloud project is not public
This is my build file. I use cmake to build the project.
name: Build
on:
push:
branches:
- develop
- feature/*
- feat/*
- fix/*
- task/*
- release*
pull_request:
types: [opened, reopened]
jobs:
build:
name: Build
runs-on: macos-latest
env:
SONAR_SCANNER_VERSION: 4.7.0.2747 # Find the latest version in the "MacOS" link on this page:
# https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarscanner-cli/
SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: . # Directory where build-wrapper output will be placed
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Download and set up sonar-scanner
env:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-macosx.zip
run: |
mkdir -p $HOME/.sonar
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-macosx/bin" >> $GITHUB_PATH
- name: Download and set up build-wrapper
env:
BUILD_WRAPPER_DOWNLOAD_URL: ${{ env.SONAR_SERVER_URL }}/static/cpp/build-wrapper-macosx-x86.zip
run: |
curl -sSLo $HOME/.sonar/build-wrapper-macosx-x86.zip ${{ env.BUILD_WRAPPER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/build-wrapper-macosx-x86.zip -d $HOME/.sonar/
echo "$HOME/.sonar/build-wrapper-macosx-x86" >> $GITHUB_PATH
- name: Run build-wrapper
run: |
mkdir build
cmake -S . -B build
build-wrapper-macosx-x86 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
And here is my sonar properties file:
sonar.projectKey=org_sal
sonar.organization=org
# This is the name and version displayed in the SonarCloud UI.
sonar.projectName=sal
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
sonar.sources=SAL/src
# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
sonar.exclusions=**/*.sh,**/*.py,**/*_Test*,SAL_Unit_Tests/**
For some reason I only see python code on SonarCloud. Here is a screenshot of SonarCloud
The screenshoot I shared and also if i go to the code section that analyzed they are all python files. If you look at the screenshot I shared above it says python only!
I created a PR for analyzing the code and i didn’t merge the PR into main branch yet. right now, it is analyzing my local branch and not main branch in sonarcloud.
They are from main branch but I did auto analyze with sonarcloud to see if the auto analyze can change the python code only to c++ code. and when you do auto analyze it analyzing the main branch. So the screenshots i shared are from main branch.
After merging the repo into main branch it worked. So as you said above SonarCloud doesn’t analyze C++ files automatically. Thank you so much for your help!