|
| 1 | +Collecting metrics |
| 2 | +================== |
| 3 | + |
| 4 | +.. toctree:: |
| 5 | + :maxdepth: 2 |
| 6 | + |
| 7 | + project_report |
| 8 | + sonar |
| 9 | + |
| 10 | +.. _direct_metrics: |
| 11 | + |
| 12 | +Direct metrics |
| 13 | +++++++++++++++ |
| 14 | + |
| 15 | +The PTB allows you to collect various metrics on the quality of your project |
| 16 | +regarding Coverage, Security, and Static Code Analysis. |
| 17 | + |
| 18 | +For each metric, there is a dedicated nox session, generating one or multiple |
| 19 | +files and based on a selected external Python tool. |
| 20 | + |
| 21 | ++------------------------------------+-----------------------------+--------------+ |
| 22 | +| Nox session | Generated files | Based on | |
| 23 | ++====================================+=============================+==============+ |
| 24 | +| ``lint:code`` | ``lint.txt``, ``lint.json`` | ``pylint`` | |
| 25 | ++------------------------------------+-----------------------------+--------------+ |
| 26 | +| ``lint:security`` | ``.security.json`` | ``bandit`` | |
| 27 | ++------------------------------------+-----------------------------+--------------+ |
| 28 | +| ``test:unit -- --coverage`` | ``.coverage`` | ``coverage`` | |
| 29 | ++------------------------------------+-----------------------------+--------------+ |
| 30 | +| ``test:integration -- --coverage`` | ``.coverage`` | ``coverage`` | |
| 31 | ++------------------------------------+-----------------------------+--------------+ |
| 32 | + |
| 33 | +These metrics are computed for each point in your build matrix, e.g. for each |
| 34 | +Python version defined in the file ``noxconfig.py``: |
| 35 | + |
| 36 | +.. code-block:: python |
| 37 | +
|
| 38 | + @dataclass(frozen=True) |
| 39 | + class Config: |
| 40 | + python_versions = ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 41 | +
|
| 42 | +The GitHub workflows of your project can: |
| 43 | + |
| 44 | +* Use a build matrix, e.g. using different Python versions as shown above |
| 45 | +* Define multiple test sessions, e.g. for distinguishing fast vs. slow or expensive tests. |
| 46 | + |
| 47 | + |
| 48 | +Reporting metrics |
| 49 | ++++++++++++++++++ |
| 50 | + |
| 51 | +Currently, within the PTB, we offer two methods by which the :ref:`direct_metrics` |
| 52 | +are summarized into reports: |
| 53 | + |
| 54 | +#. the nox session ``project:report`` |
| 55 | + This summarization tool can generate either a JSON or markdown summary where |
| 56 | + it provides an overall coverage percentage, maintainability grade, and security |
| 57 | + grade. The generated JSON follows a code-agnostic format which can be used |
| 58 | + for code quality analysis across Exasol. The markdown summary can be displayed in |
| 59 | + the GitHub Action's Summary for a given CI run. For more information, see :ref:`project_report`. |
| 60 | + |
| 61 | +#. SonarQube analysis |
| 62 | + This summarization tool feeds into a feature-rich UI provided by |
| 63 | + `Sonar <https://docs.sonarsource.com/sonarqube-server>`__. The total coverage |
| 64 | + is calculated as a percentage and visually displayed per line on the altered code. |
| 65 | + Security & linting issues are displayed in a list with links to the code & textual |
| 66 | + descriptions on why they should be fixed and how they can be fixed. Additionally, |
| 67 | + this information can be paired per project with a bot, which reports the code |
| 68 | + quality analysis results within a PR. For further details, see :ref:`sonarqube_analysis` |
| 69 | + |
| 70 | +Both of these reporting options require that the generated files from the :ref:`direct_metrics` |
| 71 | +are existing and in the expected formats. As we have metrics for different Python |
| 72 | +versions, we pass on the metrics associated with the Python version named first in |
| 73 | +attribute ``python_versions`` of class ``Config`` to the reporting metrics tools. |
| 74 | + |
| 75 | +To perform this validation, we have defined two nox sessions. Due to the direct |
| 76 | +dependence on the nox session ``project:report`` and SonarQube Analysis on the |
| 77 | +aforementioned nox sessions, all of these are executed in succession in the CI's ``report.yml``. |
| 78 | + |
| 79 | ++--------------------------+----------------------------------------------------------+ |
| 80 | +| Nox session | Actions | |
| 81 | ++==========================+==========================================================+ |
| 82 | +| ``artifacts:copy`` | * Combines coverage artifacts from various test sources | |
| 83 | +| | (unit, integration ...) | |
| 84 | +| | * Copies downloaded artifacts to their parent directory | |
| 85 | ++--------------------------+----------------------------------------------------------+ |
| 86 | +| ``artifacts:validate`` | * Verifies that the ``.lint.json``, ``.lint.json``, | |
| 87 | +| | ``.security.json``, and ``.coverage`` are present | |
| 88 | +| | * Checks that each file contains the expected attributes | |
| 89 | +| | for that file type | |
| 90 | ++--------------------------+----------------------------------------------------------+ |
0 commit comments