我想创建一个Github工作流,做以下工作。
pytest
据我所知,SonarQ需要一个文件 coverage.xml
来显示代码覆盖率。这可以通过
pytest --cov=./ --cov-report=xml --doctest-modules
根据 本文 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
. 有什么办法可以让这个工作?
错误来自于缺失 s
在 reportPaths
在 sonar-project.properties
文件。