-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (118 loc) · 4.04 KB
/
Copy pathpython-test.yml
File metadata and controls
140 lines (118 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# 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@v6.0.3
- name: Set up Python 3.14
uses: actions/setup-python@v6.2.0
with:
python-version: 3.14
- name: Install uv
uses: astral-sh/setup-uv@v8.2.0
with:
version: "0.11.21"
- 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.10", "3.14"]
django-version: ["4.2.*", "5.2.*", "6.0.*"]
exclude:
# Django 6.0 only supports Python 3.12 and above
- python-version: "3.10"
django-version: "6.0.*"
- python-version: "3.11"
django-version: "6.0.*"
# No need to test all combinations on Ubuntu
- os: "ubuntu-latest"
python-version: "3.10"
steps:
- name: Checkout code
uses: actions/checkout@v6.0.3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6.2.0
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v8.2.0
with:
version: "0.11.21"
- name: Install dependencies
run: |
uv sync --locked --group test --no-install-package django
uv pip install "django==${{ matrix.django-version }}"
uv pip freeze
- name: Run tests
run: |
uv run pytest --cov-report xml:test-reports/coverage.xml --junitxml=test-reports/pytest.xml --cov-fail-under=80
continue-on-error: true # Always continue to upload reports
- name: Check type annotations
run: |
uv run mypy --junit-xml test-reports/mypy.xml src
continue-on-error: true # Always continue to upload reports
- name: Upload coverage and test reports
# Upload coverage report only once to avoid redundancy
if: ${{ matrix.os == 'windows-latest' && matrix.python-version == '3.14' && matrix.django-version == '5.2.*' }}
uses: actions/upload-artifact@v7.0.1
with:
name: test-reports
path: test-reports/
compression-level: 9
sonarqube:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v6.0.3
with:
# No shallow clone for a better analysis
fetch-depth: 0
- name: Set up Python 3.14
uses: actions/setup-python@v6.2.0
with:
python-version: 3.14
- name: Download test reports
uses: actions/download-artifact@v8.0.1
with:
name: test-reports
- name: Extract package version
run: |
pip install setuptools-scm[simple]
echo "PACKAGE_VERSION=$(setuptools-scm --strip-dev -f plain)" >> $GITHUB_ENV
- name: Display extracted package version
run: |
echo Extracted package version: ${{ env.PACKAGE_VERSION }}
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v8.2.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
with:
args: >
--define "sonar.projectVersion=${{ env.PACKAGE_VERSION }}"
- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@v1.2.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}