From 8ceb9a86cfd49b58fcf65691c744f704361d89f1 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Thu, 9 May 2024 19:15:04 -0400 Subject: [PATCH 1/2] [CONFIG] Node script for github-actions. Split in 2: One for Coverage, the another to run multi-version/multi-OS tests. --- .github/workflows/python-coverage.yml | 46 +++++++++++++++++++++++++++ .github/workflows/python.yml | 8 +---- 2 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/python-coverage.yml diff --git a/.github/workflows/python-coverage.yml b/.github/workflows/python-coverage.yml new file mode 100644 index 00000000..5dfba6f9 --- /dev/null +++ b/.github/workflows/python-coverage.yml @@ -0,0 +1,46 @@ +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 + + - name: Setup Python + uses: actions/setup-python@master + with: + python-version: ${{ matrix.python }} + + - name: Install + run: | + pip3 install -r requirements.txt + + - name: Test + run: | + coverage run -m pytest --verbose -o log_cli=true --log-cli-level=INFO src/ + + - 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/.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) From 795ad10ff2cdd23768ad5a5e2e94105618f2f065 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Thu, 9 May 2024 21:41:23 -0400 Subject: [PATCH 2/2] [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/ --- .github/workflows/python-coverage.yml | 13 +++++++++++++ sonar-project.properties | 19 +++++++++++++++++++ tox.ini | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 sonar-project.properties create mode 100644 tox.ini diff --git a/.github/workflows/python-coverage.yml b/.github/workflows/python-coverage.yml index 5dfba6f9..035ad0c8 100644 --- a/.github/workflows/python-coverage.yml +++ b/.github/workflows/python-coverage.yml @@ -21,6 +21,8 @@ jobs: 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 @@ -44,3 +46,14 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} # required verbose: true # optional (default = false) + + - name: Install tox and any other packages + run: pip install tox + - name: Run tox + run: tox -e py + + - 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/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 diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..adf922fb --- /dev/null +++ b/tox.ini @@ -0,0 +1,16 @@ +[tox] +envlist = py39 +skipsdist = True + +[testenv] +deps = + pytest + coverage +commands = + coverage run -m pytest + coverage xml + +[coverage:run] +relative_files = True +source = src/ +branch = True