Skip to content

Commit

Permalink
Adding sonarcloud scan
Browse files Browse the repository at this point in the history
Signed-off-by: bvandekerkhof <bas.vandekerkhof@shell.com>
  • Loading branch information
bvandekerkhof committed Feb 14, 2024
1 parent eda07f5 commit 398c6f8
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/sonarcloud_analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SPDX-FileCopyrightText: 2024 Shell Global Solutions International B.V. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

name: SonarCloudAnalysis
on:
- push
jobs:
SonarCloud Analysis:
runs-on: ubuntu-latest
strategy:
matrix:
# Specify all python versions you might want to perform the actions on
python-version: [ "3.11" ]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install pytest-cov
pip install pytest-cases
pip install .
- name: Unit test with pytest
run: |
pytest --cov-report=xml --junitxml=pytest_junit.xml
- name: Fix code coverage paths
run: |
sed -i 's/\/opt\/hostedtoolcache\/Python\/.*\/site-packages/src/g' coverage.xml
sed -i 's/opt\/hostedtoolcache\/Python\/.*\/site-packages/src/g' coverage.xml
sed -i 's/\.opt\.hostedtoolcache\.Python\..*\.site-packages\.openmcmc/src/g' coverage.xml
sed -i 's/opt\.hostedtoolcache\.Python\..*\.site-packages\.openmcmc/src/g' coverage.xml
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: Upload coverage xml results
uses: actions/upload-artifact@v3
with:
name: coverage_xml
path: coverage.xml
if: ${{ always() }}
- name: Upload coverage junitxml results
uses: actions/upload-artifact@v3
with:
name: pytest_junitxml
path: pytest_junit.xml
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}
- name: SonarCloud Scan
if: ${{ always() }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.OPENMCMC_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Upload SonarCloud Scan Report
uses: actions/upload-artifact@master
with:
name: sonar-scan-log
path: .scannerwork/report-task.txt
if: ${{ always() }}
16 changes: 16 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2024 Shell Global Solutions International B.V. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0

sonar.organization=pyelq
sonar.projectKey=pyelq_openmcmc
sonar.host.url=https://sonarcloud.io
sonar.projectName=openMCMC
sonar.sources=src/
sonar.language=py
sonar.python.version=3
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.coveragePlugin=cobertura
sonar.python.xunit.reportPath=pytest_junit.xml
sonar.tests=tests
sonar.sourceEncoding=UTF-8

0 comments on commit 398c6f8

Please sign in to comment.