diff --git a/.coveragerc b/.coveragerc index 8703b933..aa747a0b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,6 @@ [run] branch = True +relative_files = True source = src/ omit = .coveragerc diff --git a/.github/workflows/python-coverage.yml b/.github/workflows/python-coverage.yml new file mode 100644 index 00000000..00b9d3a8 --- /dev/null +++ b/.github/workflows/python-coverage.yml @@ -0,0 +1,62 @@ +name: Python CI Coverage + +on: + push: + branches: [ "main", "develop", "feature/*" ] + pull_request: + branches: [ "main" ] + +env: + LOG_LEVEL: INFO + +jobs: + + build: + name: "Run CI" + strategy: + fail-fast: false + matrix: + os: ["ubuntu-latest"] + python: ['3.12'] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Setup Python + uses: actions/setup-python@master + with: + python-version: ${{ matrix.python }} + + - name: Install + run: | + pip3 install -r requirements.txt + + - name: Test an coverage collect + run: | + python3 -m coverage run -m pytest --verbose -o log_cli=true --log-cli-level=INFO src/ + + - name: Coverage Report + run: | + python3 -m coverage report + + - name: Coverage lcov + run: | + python3 -m coverage lcov -o coverage/lcov.info + + - name: Upload coverage reports to Codecov with GitHub Action + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true # optional (default = false) + + - name: Coverage XML + run: | + python3 -m coverage xml + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index d66c8819..3c38141f 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,4 +1,4 @@ -name: Python +name: Python CI Tests on: push: @@ -58,9 +58,3 @@ jobs: - name: Coverage run: | coverage report - - - name: Upload coverage reports to Codecov with GitHub Action - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} # required - verbose: true # optional (default = false) diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..60fe916f --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,19 @@ +sonar.projectKey=sir-gon_algorithm-exercises-py +sonar.organization=sir-gon + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=algorithm-exercises-py +#sonar.projectVersion=1.0 + + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +# sonar.sources=src +sonar.exclusions=**/*test.py,**/__init__.py + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 + +sonar.python.version=3.12 + +# Coverage +sonar.python.coverage.reportPaths=coverage.xml