GitHub SonarCloud 操作不扫描任何文件

问题描述 投票:0回答:1

在我的 GitHub 存储库中,我配置了 SonarCloud。我的问题是 SonarsScanner 检测到 0 个文件,因此 SonarCloud 打印“0 行代码”并且显然没有报告任何问题。

我的 sonarcloud.yml 动作配置文件如下所示:

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

执行日志没有提到任何错误:

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
...

它只是说“0 个文件索引”。

在 GitHub 上,我的主分支是分支“main”(Git 仓库的唯一分支)

有人知道吗?

github github-actions action sonarcloud sonarscanner
1个回答
0
投票

您的工作流程中缺少结帐步骤,这就是未检测到文件的原因。

添加结帐步骤后,它应该可以正常工作,即:

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

此外,您正在指定多行

args
,因此您必须相应地配置它,即使用
|
。有关详细信息,请参阅https://yaml-multiline.info/

这是另一个相关主题:

© www.soinside.com 2019 - 2024. All rights reserved.