Skip to content

Commit a2ad1e2

Browse files
authored
Add sonar to project for quality checks (#452)
* Add sonar to project for quality checks * Move pysonar to direct dependencies * Add changelog entry * Switch to nox task * Continue nox task, add to templates, & update documentation * Fix template .gitignore & inherit secrets for report * Add new nox tasks to main tasks.py * Fix to relative path from . for coverage.xml & session * Add organization as required for pysonar * Add statement to docs about adding to branch protections * Rename variable to avoid code smell, as built-in * Remove f from non-f-string * Fix typo in documentation * Move and rename to correct test folder * fixup! Rename variable to avoid code smell, as built-in * Fix class name to fit convention * Group copy_artifact tests together * Use variables to ensure names consistent throughout usually subsequent operations * Simplify test and move into correct file * Remove file check as already done before validating them * Switch validations to booleans and simplify to all or fail * Move over and simplify test for is_valid_lint_txt * Move over and simplify test for is_valid_lint_json and mirror to is_valid_lint_txt * Move over and simplify test for is_valid_security_json * Convert to handle validation error * Move over and simplify test for is_valid_coverage * Switch to simple assert * Add test for check_artifacts and switch prints to all bey stderr * Fix warnings in sonar upload output * Remove code smells where non-f-strings * Switch python_files to be Iterable[str] as only used that way & restrict bandit to source files * Add type ignore for unpacked list into session * Project fix * Fix comment * Add inherit secrets for sonar to pr-merge.ymls * Reduce scope of pylint to that of package * Update documentation with summary and make clearer private vs public repos * Re-lock dependencies * Modify documentation per review * Rename to sonar:check
1 parent dd481dc commit a2ad1e2

File tree

23 files changed

+779
-565
lines changed

23 files changed

+779
-565
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
name: CI
22

33
on:
4-
push:
5-
branches-ignore:
6-
- "github-pages/*"
7-
- "gh-pages/*"
8-
- "main"
9-
- "master"
4+
pull_request:
5+
types: [opened, synchronize, reopened]
106
schedule:
11-
# At 00:00 on every 7th day-of-month from 1 through 31. (https://crontab.guru)
7+
# At 00:00 on every 7th day-of-month from 1 through 31. (https://crontab.guru)
128
- cron: "0 0 1/7 * *"
139

1410
jobs:
15-
1611
CI:
1712
uses: ./.github/workflows/merge-gate.yml
1813
secrets: inherit
1914
permissions:
2015
contents: read
21-
2216
Metrics:
2317
needs: [ CI ]
2418
uses: ./.github/workflows/report.yml
19+
secrets: inherit
2520
permissions:
2621
contents: read

.github/workflows/pr-merge.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ jobs:
2525
metrics:
2626
needs: [ ci-job ]
2727
uses: ./.github/workflows/report.yml
28+
secrets: inherit
2829
permissions:
2930
contents: read

.github/workflows/report.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
- name: Generate Report
3636
run: poetry run -- nox -s project:report -- --format json | tee metrics.json
3737

38+
- name: Upload to sonar
39+
run: poetry run -- nox -s sonar:check -- ${{ secrets.SONAR_TOKEN }}
40+
3841
- name: Upload Artifacts
3942
uses: actions/upload-artifact@v4.6.2
4043
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ odbcconfig/odbcinst.ini
77
.html-documentation
88

99
.coverage
10+
.sonar
1011

1112
_build/
1213

doc/changes/unreleased.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
11
# Unreleased
2+
3+
## Summary
4+
This version of the PTB adds nox task `sonar:check`, see #451. This allows us to
5+
use SonarQube Cloud to analyze, visualize, & track linting, security, & coverage. In
6+
order to properly set it up, you'll need to do the following instruction for each **public** project.
7+
At this time, PTB currently does not support setting up SonarQube for a **private** project.
8+
9+
1. Specify in the `noxconfig.py` the relative path to the project's source code in `Config.source`
10+
```python
11+
source: Path = Path("exasol/toolbox")
12+
```
13+
2. Add the 'SONAR_TOKEN' to the 'Organization secrets' in GitHub (this requires a person being a GitHub organization owner).
14+
3. Activate the SonarQubeCloud App
15+
4. Create a project on SonarCloud
16+
5. Add the following information to the project's file `pyproject.toml`
17+
```toml
18+
[tool.sonar]
19+
projectKey = "com.exasol:<project-key>"
20+
hostUrl = "https://sonarcloud.io"
21+
organization = "exasol"
22+
```
23+
6. Post-merge, update the branch protections to include SonarQube analysis
24+
25+
## ✨ Features
26+
* #451: Added nox task to execute pysonar & added Sonar to the CI
27+
28+
## ⚒️ Refactorings
29+
* #451: Reduced scope of nox tasks `lint:code` (pylint) and `lint:security` (bandit) to analyze only the package code

doc/user_guide/getting_started.rst

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ forward, and you just can use the example *noxfile.py* below.
179179
180180
.. _toolbox tasks:
181181

182-
7. Setup for deploying documentation (optional)
183-
+++++++++++++++++++++++++++++++++++++++++++++++
182+
7. Set up for deploying documentation (optional)
183+
++++++++++++++++++++++++++++++++++++++++++++++++
184184
Within the `gh-pages.yml`, we use the GitHub `upload-pages-artifact` and `deploy-pages`
185185
actions. In order to properly deploy your pages, you'll need to reconfigure the GitHub
186186
Pages settings for the repo:
@@ -199,8 +199,32 @@ We also need to configure settings for github-pages environment:
199199
5. In the 'Deployment branches and tags', click 'Add deployment branch or tag rule'
200200
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)
201201

202+
8. Set up for Sonar
203+
+++++++++++++++++++
204+
PTB supports using SonarQube Cloud to analyze, visualize, & track linting, security, &
205+
coverage. In order to properly set it up, you'll need to do the following instructions
206+
for each **public** project. At this time, PTB currently does not support setting up
207+
SonarQube for a **private** project.
202208

203-
8. Go 🥜
209+
1. Specify in the `noxconfig.py` the relative path to the project's source code in `Config.source`
210+
.. code-block:: python
211+
212+
source: Path = Path("exasol/toolbox")
213+
2. Add the 'SONAR_TOKEN' to the 'Organization secrets' in GitHub (this requires a person being a GitHub organization owner).
214+
3. Activate the SonarQubeCloud App
215+
4. Create a project on SonarCloud
216+
5. Add the following information to the project's file `pyproject.toml`
217+
.. code-block:: toml
218+
219+
[tool.sonar]
220+
projectKey = "com.exasol:<project-key>"
221+
hostUrl = "https://sonarcloud.io"
222+
organization = "exasol"
223+
6. Post-merge, update the branch protections to include SonarQube analysis
224+
225+
226+
227+
9. Go 🥜
204228
+++++++++++++
205229
You are ready to use the toolbox. With *nox -l* you can list all available tasks.
206230

0 commit comments

Comments
 (0)