From a5c404faf5c2bf71e448b566a7aa2d2cc1df0f55 Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:43:09 -0600 Subject: [PATCH] SonarQube add python code coverage report (#2565) * 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 --- .github/workflows/sonarqube.yml | 23 +++++++++++++++++++ .../sonarqube/sonar-project.properties | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index b20417902..694697b94 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -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 diff --git a/internal/scripts/sonarqube/sonar-project.properties b/internal/scripts/sonarqube/sonar-project.properties index 02f74d786..1504a3f16 100644 --- a/internal/scripts/sonarqube/sonar-project.properties +++ b/internal/scripts/sonarqube/sonar-project.properties @@ -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