diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index d9230cb..24a6782 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -1,11 +1,14 @@ name: Python application -on: [push] +on: + push: + pull_request: jobs: build: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: python-version: - '3.10' @@ -18,11 +21,35 @@ jobs: with: python-version: '${{ matrix.python-version }}' - name: 'Install dependencies' - run: "python -m pip install --upgrade pip\npip install tox tox-gh-actions\n" + run: pip install tox tox-gh-actions - name: 'Test with tox' run: tox + - name: 'Upload coverage report' + if: matrix.python-version == '3.10' + uses: actions/upload-artifact@v4 + with: + name: cobertura-report + path: cobertura.xml - uses: casperdcl/deploy-pypi@v2 if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') && matrix.python-version == '3.10' with: password: ${{ secrets.pypi_token }} build: true + + upload-coverage: + needs: build + if: ${{ !cancelled() && needs.build.result == 'success' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} + runs-on: ubuntu-latest + permissions: + contents: read + code-quality: write + pull-requests: read + steps: + - uses: actions/download-artifact@v4 + with: + name: cobertura-report + - uses: actions/upload-code-coverage@v1 + with: + file: cobertura.xml + language: Python + label: code-coverage/pytest diff --git a/tox.ini b/tox.ini index 6a631bd..07e8bc0 100644 --- a/tox.ini +++ b/tox.ini @@ -7,9 +7,10 @@ envlist = py310, py312, py314, lint [testenv] -commands = pytest {posargs} +commands = pytest --cov=ros_ws --cov-report=xml:cobertura.xml {posargs} deps = pytest + pytest-cov [testenv:lint] basepython=python3.12