I am having issues getting sonar to import the results from mypy into sonar I found this which describes the format but not how to get the format out of mypy
I have gotten it running with a combination of the following. To the command that runs pre-commit in GitHub Actions: pre-commit run --all-files --color never then to the .pre-commit-config.yaml I added the following:
There are actually two jobs one for ruff and one for mypy and they upload a “mypy_log.txt” and a “ruff_log.txt” those are uploaded with the actions/upload-artifact@v3 and then downloaded with the actions/download-artifact@v3 in another workflow for just sonarcloud that runs and I see it finding the files but I do not see it actually importing any issues:
the job that runs the sonarcloud GitHub Action “job”:
INFO: Sensor Python Sensor [python]
INFO: Using cached data to retrieve global symbols.
INFO: Cached information of global symbols will be used for 148 out of 148 main files. Global symbols will be recomputed for the remaining files.
INFO: Fully optimized analysis can be performed for 259 out of 259 files.
INFO: Partially optimized analysis can be performed for 259 out of 259 files.
INFO: Starting global symbols computation
INFO: 0 source files to be analyzed
INFO: 0/0 source files have been analyzed
INFO: Starting rules execution
INFO: 259 source files to be analyzed
INFO: 259/259 source files have been analyzed
INFO: The Python analyzer was able to leverage cached data from previous analyses for 259 out of 259 files. These files were not parsed.
INFO: Sensor Python Sensor [python] (done) | time=1616ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Python test coverage
INFO: Parsing report '/github/workspace/coverage.xml'
ERROR: Cannot resolve the file path '<file-path>.py' of the coverage report, the file does not exist in all 'source'.
ERROR: Cannot resolve 3 file paths, ignoring coverage measures for those files
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=285ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=55ms
INFO: Sensor Import of Mypy issues [python]
INFO: Sensor Import of Mypy issues [python] (done) | time=103ms
INFO: Sensor Import of Ruff issues [python]
INFO: Importing /github/workspace/ruff_log.txt
ERROR: No issues information will be saved as the report file '/github/workspace/ruff_log.txt' can't be read. ParseException: null
INFO: Sensor Import of Ruff issues [python] (done) | time=10ms
The two files look very close to what you suggest ending in:
ruff_log.txt: Found 251 errors.
mypy_log.txt: Found 353 errors in 106 files (checked 109 source files)
so there are errors that should be loaded but I cannot see them anywhere in sonarcloud.
The ERROR: No issues information will be saved as the report file '/github/workspace/ruff_log.txt' can't be read. ParseException: null tells me that there is a reaason the ruff log might not be parsed but I should at least be seeing the mypy issues.
I have gotten the mypy side of it working and now I am just working to update to get the ruff stuff. I am working on getting that file generated right now I am using the following:
This is a section of our GitHub actions:
# The --exit-zero is because the pre-commit run catches the errors this is only for report generation
- name: Generate Ruff report
if: always()
run: |
pip install ruff
ruff --exit-zero --output-file ruff_report.json --output-format json ./<namespace> ./tests
Is this the same general command you used to generate the file you sent me.
The issue could be related to this one that I opened in ruff
Error from the sonarcloud GitHub Action Job with obvious redaction of namespaces, module names and file name, I also updated the warning to put each file on a separate line as it was a giant blob and a bit unreadable
INFO: Importing /github/workspace/ruff_report.json
WARN: Failed to resolve 27 file path(s) in Ruff report. No issues imported related to file(s): /home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file0>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file1>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file2>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file3>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file4>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file5>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file6>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file7>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file8>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file9>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file10>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file11>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file12>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file13>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file14>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file15>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file16>.py;
/home/runner/work/<library-name>/<library-name>/<namespace>/<module-name>/<file16>.py;
/home/runner/work/<library-name>/<library-name>/tests/conftest.py;
/home/runner/work/<library-name>/<library-name>/tests/<namespace>/<module-name>/<file17>.py;...
INFO: Sensor Import of Ruff issues [python] (done) | time=19ms
Thank you for reporting this issue and for the detailed explanation! There is an issue as we try to resolve two different absolute paths. I have created this ticket in order to track our progress on this task.