Skip to content

Commit

Permalink
SonarQube add python code coverage report (#2565)
Browse files Browse the repository at this point in the history
* run code coverage before SonarQube scan

* generate xml report and configure SQ to read coverage.xml

* exclude more files from code coverage report

* exclude more files that should not be included in the code coverage report

* more changes to code coverage exclude list

* removed bad characters accidentally added

* exclude cyclone plotter wrapper because it is excluded from code coverage report
  • Loading branch information
georgemccabe authored Apr 25, 2024
1 parent c80df91 commit a5c404f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ jobs:
# Disable shallow clones for better analysis
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'

- name: Install Python Test Dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r internal/tests/pytests/requirements.txt
- name: Run Pytests
run: coverage run -m pytest internal/tests/pytests
env:
METPLUS_TEST_OUTPUT_BASE: ${{ runner.workspace }}/pytest_output

- name: Output coverage report
run: coverage report -m
if: always()

- name: Generate XML coverage report
run: coverage xml
if: always()

- name: Get branch name
id: get_branch_name
run: echo branch_name=${GITHUB_REF#refs/heads/} >> $GITHUB_OUTPUT
Expand Down
3 changes: 2 additions & 1 deletion internal/scripts/sonarqube/sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ sonar.projectName=METplus
sonar.projectVersion=SONAR_PROJECT_VERSION
sonar.branch.name=SONAR_BRANCH_NAME
sonar.sources=docs,internal,manage_externals,metplus,parm,produtil,ush
sonar.coverage.exclusions=internal/tests/**
sonar.coverage.exclusions=internal/tests/**,parm/**,internal/scripts/**,manage_externals/**,docs/**,produtil/**,ush/**,metplus/wrappers/cyclone_plotter_wrapper.py
sonar.python.coverage.reportPaths=coverage.xml
sonar.sourceEncoding=UTF-8

# SonarQube server
Expand Down

0 comments on commit a5c404f

Please sign in to comment.