mirror of
https://github.com/ankitects/anki.git
synced 2026-09-10 15:48:11 -04:00
## Linked issue Closes #4995 ## Summary / motivation Bedges available: [](https://sonarcloud.io/summary/new_code?id=ankitects_anki) [](https://sonarcloud.io/summary/new_code?id=ankitects_anki) [](https://sonarcloud.io/summary/new_code?id=ankitects_anki) [](https://sonarcloud.io/summary/new_code?id=ankitects_anki) [](https://sonarcloud.io/summary/new_code?id=ankitects_anki) [](https://sonarcloud.io/summary/new_code?id=ankitects_anki) [](https://sonarcloud.io/summary/new_code?id=ankitects_anki) **[SONAR DASHBOARD](https://sonarcloud.io/project/overview?id=ankitects_anki)** Integrates SonarCloud into the CI pipeline as a proof of concept to evaluate whether it surfaces actionable quality and security insights for this codebase. Changes: - Added `sonar-project.properties` configuring sources (`pylib`, `qt`, `ts`, `rslib`) and coverage report paths - Extended `tools/coverage/coverage-py` (and `.bat`) to emit `coverage.xml` (Cobertura) - Extended `tools/coverage/coverage-ts` (and `.bat`) to emit `lcov.info` via the V8 provider - Extended `tools/coverage/coverage-rust` (and `.bat`) to emit `lcov.info` via `cargo-llvm-cov report` - Added a `SonarCloud Scan` step to the `check-linux` CI job, running after all checks pass and before the build cache is saved ## How to test ### Details **1. Install sonar-scanner** ```bash brew install sonar-scanner ``` **2. Generate and configure a token** Go to [sonarcloud.io](https://sonarcloud.io/) → My Account → Security → Generate Token Copy the generated token and export it in your shell: ``` export SONAR_TOKEN=your_token_here ``` **3. Generate coverage reports** ``` just test --coverage ``` Expected output files: - out/coverage/python-pylib/coverage.xml - out/coverage/python-qt/coverage.xml - out/coverage/typescript/lcov.info - out/coverage/rust/lcov.info **4. Run the scanner manually** ``` sonar-scanner ``` Results will appear in the SonarCloud dashboard To test coverage generation locally: ```bash just coverage # verify files exist: # out/coverage/python-pylib/coverage.xml # out/coverage/python-qt/coverage.xml # out/coverage/typescript/lcov.info # out/coverage/rust/lcov.info ```
32 lines
1.2 KiB
Batchfile
32 lines
1.2 KiB
Batchfile
@echo off
|
|
setlocal
|
|
|
|
if "%1"=="pylib" (
|
|
set "PYTHONPATH=out/pylib"
|
|
set "source=pylib/anki"
|
|
set "outdir=out\coverage\python-pylib"
|
|
set "tests=pylib/tests"
|
|
set "threshold=63"
|
|
) else if "%1"=="qt" (
|
|
set "PYTHONPATH=pylib;out/pylib;out/qt;qt/tools"
|
|
set "source=qt/aqt,qt/tools"
|
|
set "outdir=out\coverage\python-qt"
|
|
set "tests=qt/tests"
|
|
set "threshold=20"
|
|
) else (
|
|
echo Usage: %0 [pylib^|qt] [--html]
|
|
exit /b 1
|
|
)
|
|
|
|
set "ANKI_TEST_MODE=1"
|
|
if not exist %outdir% mkdir %outdir%
|
|
out\pyenv\Scripts\python -m coverage run --source=%source% --data-file=%outdir%\.coverage -m pytest -p no:cacheprovider %tests% || exit /b 1
|
|
out\pyenv\Scripts\python -m coverage json --data-file=%outdir%\.coverage -o %outdir%\coverage-summary.json || exit /b 1
|
|
out\pyenv\Scripts\python -m coverage xml --data-file=%outdir%\.coverage -o %outdir%\coverage.xml || exit /b 1
|
|
out\pyenv\Scripts\python -m coverage report --data-file=%outdir%\.coverage --fail-under=%threshold% || exit /b 1
|
|
|
|
if "%2"=="--html" (
|
|
out\pyenv\Scripts\python -m coverage html --data-file=%outdir%\.coverage -d %outdir%\html --fail-under=%threshold% || exit /b 1
|
|
echo Python %1 coverage report: %outdir%\html\index.html
|
|
)
|