In my GitHub repository, I configured SonarCloud. My problem is that SonarsScanner detects 0 files, so SonarCloud prints "0 Lines of Code" and obviously does not report any issue.
My sonarcloud.yml action configuration file looks like so:
name: Analyse SonarCloud
on:
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
sonar:
runs-on: ubuntu-latest
steps:
- name: Analyze with SonarCloud
uses: SonarSource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args:
-Dsonar.projectKey=republique-et-canton-de-geneve_noms-geographiques
-Dsonar.organization=etat-de-geneve-github
The execution logs does not mention any error:
Run SonarSource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049
with:
args: -Dsonar.projectKey=republique-et-canton-de-geneve_noms-geographiques -Dsonar.organization=etat-de-geneve-github
projectBaseDir: .
env:
GITHUB_TOKEN: ***
SONAR_TOKEN: ***
/usr/bin/docker run --name cf9bf4a74d279458db77eb23db470230f_a38639 --label 49859c --workdir /github/workspace --rm -e "GITHUB_TOKEN" -e "SONAR_TOKEN" -e "INPUT_ARGS" -e "INPUT_PROJECTBASEDIR" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/noms-geographiques/noms-geographiques":"/github/workspace" 49859c:f9bf4a74d279458db77eb23db470230f -Dsonar.projectKey=republique-et-canton-de-geneve_noms-geographiques -Dsonar.organization=etat-de-geneve-github
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.14 Alpine (64-bit)
INFO: Linux 5.15.0-1033-azure amd64
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Scanner configuration file: /opt/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarCloud
INFO: Default locale: "en_US", source code encoding: "UTF-8" (analysis is platform dependent)
INFO: Load global settings
INFO: Load global settings (done) | time=543ms
INFO: Server id: 1BD809FA-AWHW8ct9-T_TB3XqouNu
INFO: User cache: /opt/sonar-scanner/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=519ms
INFO: Load/download plugins (done) | time=3725ms
INFO: Loaded core extensions: developer-scanner
INFO: Found an active CI vendor: 'Github Actions'
INFO: Load project settings for component key: 'republique-et-canton-de-geneve_noms-geographiques'
INFO: Load project settings for component key: 'republique-et-canton-de-geneve_noms-geographiques' (done) | time=520ms
INFO: Process project properties
INFO: Execute project builders
INFO: Execute project builders (done) | time=6ms
INFO: Project key: republique-et-canton-de-geneve_noms-geographiques
INFO: Base dir: /github/workspace
INFO: Working dir: /github/workspace/.scannerwork
INFO: Load project branches
INFO: Load project branches (done) | time=508ms
INFO: Check ALM binding of project 'republique-et-canton-de-geneve_noms-geographiques'
INFO: Detected project binding: BOUND
INFO: Check ALM binding of project 'republique-et-canton-de-geneve_noms-geographiques' (done) | time=489ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=484ms
INFO: Load branch configuration
INFO: Github event: push
INFO: Auto-configuring branch main
INFO: Load branch configuration (done) | time=7ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=572ms
INFO: Load active rules
INFO: Load active rules (done) | time=5949ms
WARN: SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings.
INFO: Organization key: etat-de-geneve-github
INFO: Branch name: main, type: long-lived
INFO: Load project repositories
INFO: Load project repositories (done) | time=534ms
INFO: Indexing files...
INFO: Project configuration:
INFO: Excluded sources: **/build-wrapper-dump.json
INFO: 0 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: ------------- Run sensors on module republique-et-canton-de-geneve_noms-geographiques
...
It simply says "0 files indexed".
On GitHub, my main branch is branch "main" (the only branch of the Git repository).
Does anybody have a clue?
The checkout step is missing in your workflow that's why no files are detected.
Once you add the checkout step, it should work fine i.e.:
name: Analyse SonarCloud
on:
push:
branches: [ "main" ]
workflow_dispatch:
jobs:
sonar:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Analyze with SonarCloud
uses: SonarSource/sonarcloud-github-action@de2e56b42aa84d0b1c5b622644ac17e505c9a049
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: |
-Dsonar.projectKey=republique-et-canton-de-geneve_noms-geographiques
-Dsonar.organization=etat-de-geneve-github
Also, you are specifying multiline args
so you have to configure it accordingly i.e. with |
. See https://yaml-multiline.info/ for more details.
Here's another relevant thread: