Github 操作,Python 覆盖范围和 Sonarqube

Github Actions, Python Coverage and Sonar Qube

我想创建一个 Github 工作流来执行以下操作:

  1. 使用 pytest
  2. 测试我的代码
  3. 触发 Sonar Qube Cloud 分析代码并显示我的测试覆盖率!

据我了解,SonarQ 需要一个文件coverage.xml 来显示代码覆盖率。这可以用

生成
pytest --cov=./ --cov-report=xml --doctest-modules

根据 this article coverage.xml 应该在 /github/workspace/coverage.xml 下可用。

因此,我在项目的根文件夹中指定我的sonar-project.properties

sonar.organization=pokemate
sonar.projectKey=PokeMate_name-generator
sonar.sources=.
sonar.python.coverage.reportPath=/github/workspace/coverage.xml

我的动作文件build.yml:

on:
  push:
    branches:
      - master
      - develop
      - sonar-qube-setup

jobs:
  build:
    runs-on:
      - ubuntu-latest

    steps:
      # Checkout repo
      - uses: actions/checkout@v2

      # Dependencies
      - name: Set up Python 3.7
        uses: actions/setup-python@v1
        with:
          python-version: 3.7

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt

      # Test
      - name: Test with pytest
        run: |
          pytest --cov=./ --cov-report=xml --doctest-modules

      # Sonar Qube
      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

然而,在 SonarQ 上它仍然显示 0% 的测试覆盖率,这可能是因为它找不到 coverage.xml。知道如何进行这项工作吗?

错误来自 sonar-project.properties 文件的 reportPaths 中缺少 s