Skip to content

Commit dacca29

Browse files
committed
Move sonar configuration to sonar file
1 parent 0cb855f commit dacca29

File tree

2 files changed

+84
-63
lines changed

2 files changed

+84
-63
lines changed
Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,82 @@
11
.. _sonarqube_analysis:
22

3-
SonarQube Analysis
4-
------------------
3+
SonarQube analysis
4+
==================
5+
6+
The PTB supports using SonarQube Cloud to analyze, visualize, & track linting, security,
7+
& coverage. All of our Python projects should be evaluated against the `Exasol Way`_
8+
and subscribe to the
9+
`Clean as You Code <https://docs.sonarsource.com/sonarqube-server/9.8/user-guide/clean-as-you-code/>`__
10+
methodology. If code modified in a PR does not satisfy the aforementioned criteria, we
11+
will receiving a failing (red) SonarQube analysis.
12+
13+
Additionally, per project, we enact a GitHub bot (differs based on :ref:`configuration`,
14+
which reports the status of the Sonar analysis into a PR as a stylized comment and as
15+
a workflow result. Depending on the overall state of a project (i.e. new vs established),
16+
we can require the passing of the workflow result in the branch protections, which means
17+
that a passing Sonar analysis would be required for merging a PR.
18+
19+
.. _configuration:
520

621
Configuration
7-
^^^^^^^^^^^^^
22+
+++++++++++++
23+
24+
.. _configure_sonar_public_project:
25+
26+
**Public** project
27+
^^^^^^^^^^^^^^^^^^^^^^^^
28+
1. Specify in the ``noxconfig.py`` the relative path to the project's source code in ``Config.source``
29+
.. code-block:: python
30+
31+
source: Path = Path("exasol/<project-source-folder>")
32+
2. Add the 'SONAR_TOKEN' to the 'Organization secrets' in GitHub
33+
3. Activate the `SonarQubeCloud App <https://github.com/apps/sonarqubecloud>`__
34+
4. Create a project on `SonarCloud <https://sonarcloud.io>`__
35+
5. Add the following information to the project's file ``pyproject.toml``
36+
.. code-block:: toml
37+
38+
[tool.sonar]
39+
projectKey = "com.exasol:<project-key>"
40+
hostUrl = "https://sonarcloud.io"
41+
organization = "exasol"
42+
exclusions = "<source-directory>/version.py,<source_directory>/<directory-to-ignore>/*"
43+
6. Post-merge, update the branch protections to include SonarQube analysis
44+
45+
* This should only be done when tests exist for the project, & that the project is
46+
at a state in which enforced code coverage would not be a burden. For new projects,
47+
we recommend creating an issue to add the SonarQube analysis to the branch protections
48+
at a later point. In such scenarios, SonarQube analysis will still report its analysis
49+
results to the PR, but it will not prevent the PR from being merged.
50+
51+
.. _configure_sonar_private_project:
52+
53+
**Private** project
54+
^^^^^^^^^^^^^^^^^^^
55+
.. note::
56+
As of 2025-07-29, we do not currently have a private project configured. Thus,
57+
these instructions should be scrutinized and refined upon the configuration of one.
58+
59+
1. Specify in the ``noxconfig.py`` the relative path to the project's source code in ``Config.source``
60+
.. code-block:: python
61+
62+
source: Path = Path("exasol/<project-source-folder>")
63+
2. Add the individual 'PRIVATE_SONAR_TOKEN' to the 'Organization secrets' in GitHub
64+
3. Activate the `exasonarqubeprchecks App <https://github.com/apps/exasonarqubeprchecks>`__
65+
4. Create a project on https://sonar.exasol.com
66+
5. Add the following information to the project's file `pyproject.toml`
67+
.. code-block:: toml
68+
69+
[tool.sonar]
70+
projectKey = "com.exasol:<project-key>"
71+
hostUrl = "https://sonar.exasol.com"
72+
organization = "exasol"
73+
exclusions = "<source-directory>/version.py,<source_directory>/<directory-to-ignore>/*"
74+
6. Post-merge, update the branch protections to include SonarQube analysis from exasonarqubeprchecks
75+
76+
* This should only be done when tests exist for the project, & that the project is
77+
at a state in which enforced code coverage would not be a burden. For new projects,
78+
we recommend creating an issue to add the SonarQube analysis to the branch protections
79+
at a later point. In such scenarios, SonarQube analysis will still report its analysis
80+
results to the PR, but it will not prevent the PR from being merged.
81+
82+
.. _Exasol Way: https://sonarcloud.io/organizations/exasol/quality_gates/show/AXxvLH-3BdtLlpiYmZhh

doc/user_guide/getting_started.rst

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -201,67 +201,13 @@ We also need to configure settings for github-pages environment:
201201
5. In the 'Deployment branches and tags', click 'Add deployment branch or tag rule'
202202
6. Select 'Ref type' to be 'Tag' and set the 'Name pattern' to `[0-9]*.[0-9]*.[0-9]*` (or whatever matches that repo's tags)
203203

204-
8. Set up for Sonar
204+
8. Set up Sonar
205205
+++++++++++++++++++
206-
PTB supports using SonarQube Cloud to analyze, visualize, & track linting, security, &
207-
coverage. All of our Python projects are evaluated against the
208-
`Exasol Way <https://sonarcloud.io/organizations/exasol/quality_gates/show/AXxvLH-3BdtLlpiYmZhh>`__
209-
and subscribe to the
210-
`Clean as You Code <https://docs.sonarsource.com/sonarqube-server/9.8/user-guide/clean-as-you-code/>`__
211-
methodology, which means that SonarQube analysis will fail and, if its included in the branch protections, block a PR
212-
if code modified in that PR does not meet the standards of the Exasol Way.
213-
214-
In order to set up Sonar, you will need to perform the following instructions.
215-
216-
For a **public** project
217-
^^^^^^^^^^^^^^^^^^^^^^^^
218-
1. Specify in the `noxconfig.py` the relative path to the project's source code in `Config.source`
219-
.. code-block:: python
220-
221-
source: Path = Path("exasol/<project-source-folder>")
222-
2. Add the 'SONAR_TOKEN' to the 'Organization secrets' in GitHub (this requires a person being a GitHub organization owner)
223-
3. Activate the `SonarQubeCloud App <https://github.com/apps/sonarqubecloud>`_
224-
4. Create a project on SonarCloud
225-
5. Add the following information to the project's file `pyproject.toml`
226-
.. code-block:: toml
227-
228-
[tool.sonar]
229-
projectKey = "com.exasol:<project-key>"
230-
hostUrl = "https://sonarcloud.io"
231-
organization = "exasol"
232-
exclusions = "<source-directory>/version.py,<source_directory>/<directory-to-ignore>/*"
233-
6. Post-merge, update the branch protections to include SonarQube analysis
234-
235-
* This should only be done when tests exist for the project, & that the project is
236-
at a state in which enforced code coverage would not be a burden. For new projects,
237-
we recommend creating an issue to add the SonarQube analysis to the branch protections
238-
at a later point. In such scenarios, SonarQube analysis will still report its analysis
239-
results to the PR, but it will not prevent the PR from being merged.
240-
241-
For a **private** project
242-
^^^^^^^^^^^^^^^^^^^^^^^^^
243-
1. Specify in the `noxconfig.py` the relative path to the project's source code in `Config.source`
244-
.. code-block:: python
245-
246-
source: Path = Path("exasol/<project-source-folder>")
247-
2. Add the 'PRIVATE_SONAR_TOKEN' to the 'Organization secrets' in GitHub (this requires a person being a GitHub organization owner)
248-
3. Activate the `exasonarqubeprchecks App <https://github.com/apps/exasonarqubeprchecks>`_
249-
4. Create a project on https://sonar.exasol.com
250-
5. Add the following information to the project's file `pyproject.toml`
251-
.. code-block:: toml
252-
253-
[tool.sonar]
254-
projectKey = "com.exasol:<project-key>"
255-
hostUrl = "https://sonar.exasol.com"
256-
organization = "exasol"
257-
exclusions = "<source-directory>/version.py,<source_directory>/<directory-to-ignore>/*"
258-
6. Post-merge, update the branch protections to include SonarQube analysis from exasonarqubeprchecks
259-
260-
* This should only be done when tests exist for the project, & that the project is
261-
at a state in which enforced code coverage would not be a burden. For new projects,
262-
we recommend creating an issue to add the SonarQube analysis to the branch protections
263-
at a later point. In such scenarios, SonarQube analysis will still report its analysis
264-
results to the PR, but it will not prevent the PR from being merged.
206+
207+
Look at the configuration of Sonar for a:
208+
209+
* :ref:`configure_sonar_public_project`
210+
* :ref:`configure_sonar_private_project`
265211

266212
9. Go 🥜
267213
+++++++++++++

0 commit comments

Comments
 (0)