Skip to content

Generate mypy reports for sonarqube #38

Generate mypy reports for sonarqube

Generate mypy reports for sonarqube #38

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Test Python package
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.13
uses: actions/setup-python@v3
with:
python-version: 3.13
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "0.8.14"
- name: Install dependencies
# TODO: Is this necessary? Maybe we just install pre-commit directly?
run: |
uv sync --locked --dev
uv pip freeze
- name: Lint with pre-commit
# TODO: Consider caching pre-commit installation
run: |
uv run pre-commit run --all-files --show-diff-on-failure
test:
runs-on: ${{ matrix.os }}
needs: lint
strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest", "windows-latest"]
python-version: ["3.9", "3.13", "3.14.0-rc.2"]
django-version: ["4.2.*", "5.2.*"]
exclude:
# Django 5.2 only supports Python 3.10 and above
- python-version: "3.9"
django-version: "5.2.*"
# No need to test all combinations on Ubuntu
- os: "ubuntu-latest"
python-version: "3.9"
- os: "ubuntu-latest"
python-version: "3.14.0-rc.2"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v6
with:
version: "0.8.14"
- name: Install dependencies
# TODO: set up caching for uv
run: |
uv sync --locked --dev --no-install-package django
uv pip install "django==${{ matrix.django-version }}"
uv pip freeze
- name: Test with pytest
run: |
uv run pytest --cov-report xml:coverage.xml --junitxml=pytest.xml --cov-fail-under=80
- name: Upload coverage and test reports
# Upload coverage report only once to avoid redundancy
if: ${{ matrix.os == 'windows-latest' && matrix.python-version == '3.13' && matrix.django-version == '5.2.*' }}
uses: actions/[email protected]
with:
name: test-report
path: |
coverage.xml
pytest.xml
sonarqube:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# No shallow clone for a better analysis
fetch-depth: 0
- name: Set up Python 3.13
uses: actions/setup-python@v3
with:
python-version: 3.13
- name: Install Mypy
run: |
python -m pip install mypy django-stubs types-pywin32
- name: Run MyPy
run: |
mypy --strict --junit-xml mypy.xml src
continue-on-error: true
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: test-report
- name: SonarQube Scan
uses: SonarSource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}