Skip to content

Commit abe8460

Browse files
author
Gonzalo Diaz
committed
[CONFIG] Node script for github-actions, sonarcloud automatic scan disabled (to enable coverage support):
https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/python-test-coverage/
1 parent 8ceb9a8 commit abe8460

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

.coveragerc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[run]
22
branch = True
3-
source = src/
3+
include =
4+
src/*
45
omit =
56
.coveragerc
67
*test.py

.github/workflows/python-coverage.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
runs-on: ${{ matrix.os }}
2222
steps:
2323
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
24+
with:
25+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
2426

2527
- name: Setup Python
2628
uses: actions/setup-python@master
@@ -31,16 +33,30 @@ jobs:
3133
run: |
3234
pip3 install -r requirements.txt
3335
34-
- name: Test
36+
- name: Test an coverage collect
37+
run: |
38+
python3 -m coverage run -m pytest --verbose -o log_cli=true --log-cli-level=INFO src/
39+
40+
- name: Coverage Report
3541
run: |
36-
coverage run -m pytest --verbose -o log_cli=true --log-cli-level=INFO src/
42+
python3 -m coverage report
3743
38-
- name: Coverage
44+
- name: Coverage lcov
3945
run: |
40-
coverage report
46+
python3 -m coverage lcov -o coverage/lcov.info
4147
4248
- name: Upload coverage reports to Codecov with GitHub Action
4349
uses: codecov/codecov-action@v4
4450
with:
4551
token: ${{ secrets.CODECOV_TOKEN }} # required
4652
verbose: true # optional (default = false)
53+
54+
- name: Coverage XML
55+
run: |
56+
python3 -m coverage xml
57+
58+
- name: SonarCloud Scan
59+
uses: SonarSource/sonarcloud-github-action@master
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
62+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

sonar-project.properties

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sonar.projectKey=sir-gon_algorithm-exercises-py
2+
sonar.organization=sir-gon
3+
4+
# This is the name and version displayed in the SonarCloud UI.
5+
#sonar.projectName=algorithm-exercises-py
6+
#sonar.projectVersion=1.0
7+
8+
9+
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
10+
# sonar.sources=src
11+
sonar.exclusions=**/*test.py,**/__init__.py
12+
13+
# Encoding of the source code. Default is default system encoding
14+
#sonar.sourceEncoding=UTF-8
15+
16+
sonar.python.version=3.12
17+
18+
# Coverage
19+
sonar.python.coverage.reportPaths=coverage.xml

0 commit comments

Comments
 (0)