|
1 | 1 | --- |
2 | | - |
3 | | -name: CI |
| 2 | +name: Test |
4 | 3 |
|
5 | 4 | on: |
6 | 5 | push: |
|
14 | 13 | workflow_dispatch: {} |
15 | 14 |
|
16 | 15 | # We share Vuforia credentials and therefore Vuforia databases across |
17 | | -# workflows. |
18 | | -# We therefore want to run only one workflow at a time. |
| 16 | +# workflows. We therefore want to run only one workflow at a time. |
19 | 17 | concurrency: vuforia_credentials |
20 | 18 |
|
21 | 19 | jobs: |
22 | | - build: |
23 | | - |
| 20 | + # CI tests with matrix |
| 21 | + ci-tests: |
24 | 22 | runs-on: ubuntu-latest |
25 | | - |
26 | 23 | strategy: |
27 | 24 | fail-fast: false |
28 | 25 | matrix: |
@@ -120,9 +117,6 @@ jobs: |
120 | 117 |
|
121 | 118 | steps: |
122 | 119 | - uses: actions/checkout@v5 |
123 | | - with: |
124 | | - # See https://github.com/codecov/codecov-action/issues/190. |
125 | | - fetch-depth: 2 |
126 | 120 |
|
127 | 121 | - name: Install uv |
128 | 122 | uses: astral-sh/setup-uv@v6 |
@@ -158,54 +152,189 @@ jobs: |
158 | 152 |
|
159 | 153 | - name: Run tests |
160 | 154 | run: | |
161 | | - uv run --extra=dev pytest \ |
162 | | - -s \ |
163 | | - -vvv \ |
164 | | - --showlocals \ |
165 | | - --exitfirst \ |
166 | | - --cov=src/ \ |
167 | | - --cov=tests/ \ |
168 | | - --cov-report=xml \ |
169 | | - ${{ matrix.ci_pattern }} |
| 155 | + uv run --extra=dev \ |
| 156 | + coverage run \ |
| 157 | + --parallel-mode \ |
| 158 | + --source=src/ \ |
| 159 | + --source=tests/ \ |
| 160 | + -m pytest \ |
| 161 | + -s \ |
| 162 | + -vvv \ |
| 163 | + --showlocals \ |
| 164 | + --exitfirst \ |
| 165 | + ${{ matrix.ci_pattern }} |
170 | 166 | env: |
171 | 167 | UV_PYTHON: ${{ matrix.python-version }} |
172 | 168 |
|
173 | | - - name: Show coverage file |
| 169 | + - name: Sanitize pattern for artifact name |
| 170 | + id: sanitize |
| 171 | + run: | |
| 172 | + SANITIZED_PATTERN=$(echo "${{ matrix.ci_pattern }}" | sed 's/::/-/g' | sed 's/:/-/g' | sed 's|/|-|g') |
| 173 | + echo "name=coverage-data-ci-${{ matrix.python-version }}-${SANITIZED_PATTERN}" >> "$GITHUB_OUTPUT" |
| 174 | +
|
| 175 | + - name: Upload coverage data |
| 176 | + uses: actions/upload-artifact@v4 |
| 177 | + with: |
| 178 | + name: ${{ steps.sanitize.outputs.name }} |
| 179 | + path: .coverage.* |
| 180 | + include-hidden-files: true |
| 181 | + if-no-files-found: error |
| 182 | + |
| 183 | + # Skip tests |
| 184 | + skip-tests: |
| 185 | + runs-on: ubuntu-latest |
| 186 | + strategy: |
| 187 | + matrix: |
| 188 | + python-version: ['3.13'] |
| 189 | + platform: [ubuntu-latest] |
| 190 | + |
| 191 | + steps: |
| 192 | + - uses: actions/checkout@v5 |
| 193 | + |
| 194 | + - name: Install uv |
| 195 | + uses: astral-sh/setup-uv@v6 |
| 196 | + with: |
| 197 | + enable-cache: true |
| 198 | + cache-dependency-glob: '**/pyproject.toml' |
| 199 | + |
| 200 | + - name: Set secrets file |
| 201 | + run: | |
| 202 | + cp ./vuforia_secrets.env.example ./vuforia_secrets.env |
| 203 | +
|
| 204 | + - name: Run tests |
174 | 205 | run: | |
175 | | - # Sometimes we have been sure that we have 100% coverage, but codecov |
176 | | - # says otherwise. |
| 206 | + uv run --extra=dev \ |
| 207 | + coverage run \ |
| 208 | + --parallel-mode \ |
| 209 | + --source=src/ \ |
| 210 | + --source=tests/ \ |
| 211 | + -m pytest \ |
| 212 | + --skip-docker_build_tests \ |
| 213 | + --skip-docker_in_memory \ |
| 214 | + --skip-mock \ |
| 215 | + --skip-real \ |
| 216 | + --capture=no \ |
| 217 | + -vvv \ |
| 218 | + --exitfirst \ |
| 219 | + . |
| 220 | + env: |
| 221 | + UV_PYTHON: ${{ matrix.python-version }} |
| 222 | + |
| 223 | + - name: Upload coverage data |
| 224 | + uses: actions/upload-artifact@v4 |
| 225 | + with: |
| 226 | + name: coverage-data-skip-tests-${{ matrix.python-version }} |
| 227 | + path: .coverage.* |
| 228 | + include-hidden-files: true |
| 229 | + if-no-files-found: error |
| 230 | + |
| 231 | + # Windows tests |
| 232 | + windows-tests: |
| 233 | + runs-on: windows-latest |
| 234 | + strategy: |
| 235 | + matrix: |
| 236 | + python-version: ['3.13'] |
| 237 | + |
| 238 | + steps: |
| 239 | + - uses: actions/checkout@v5 |
| 240 | + |
| 241 | + - name: Install uv |
| 242 | + uses: astral-sh/setup-uv@v6 |
| 243 | + with: |
| 244 | + enable-cache: true |
| 245 | + cache-dependency-glob: '**/pyproject.toml' |
| 246 | + |
| 247 | + - name: Set secrets file |
| 248 | + run: | |
| 249 | + cp ./vuforia_secrets.env.example ./vuforia_secrets.env |
| 250 | +
|
| 251 | + - name: Run tests |
| 252 | + shell: bash |
| 253 | + run: | |
| 254 | + # We use pytest-xdist to make this run much faster. |
| 255 | + # The downside is that we cannot use -s / --capture=no. |
| 256 | + # |
| 257 | + # We use coverage to collect coverage data but we currently |
| 258 | + # do not upload / use it because combining Windows and Linux |
| 259 | + # coverage is challenging. |
177 | 260 | # |
178 | | - # We show the coverage file here to help with debugging. |
179 | | - # https://github.com/VWS-Python/vws-python-mock/issues/708 |
180 | | - cat ./coverage.xml |
181 | | -
|
182 | | - # We run this job on every PR, on every merge to main, and nightly. |
183 | | - # This causes us to hit an issue with Codecov. |
184 | | - # |
185 | | - # We see "Too many uploads to this commit.". |
186 | | - # See https://community.codecov.io/t/too-many-uploads-to-this-commit/2574. |
187 | | - # |
188 | | - # To work around this, we do not upload coverage data on scheduled runs. |
189 | | - # We print the event name here to help with debugging. |
190 | | - - name: Show event name |
| 261 | + # We therefore have a few ``# pragma: no cover`` statements. |
| 262 | + uv run --extra=dev \ |
| 263 | + coverage run \ |
| 264 | + --parallel-mode \ |
| 265 | + --source=src/ \ |
| 266 | + --source=tests/ \ |
| 267 | + -m pytest \ |
| 268 | + --skip-real \ |
| 269 | + -vvv \ |
| 270 | + --exitfirst \ |
| 271 | + -n auto \ |
| 272 | + . |
| 273 | + env: |
| 274 | + UV_PYTHON: ${{ matrix.python-version }} |
| 275 | + |
| 276 | + coverage: |
| 277 | + name: Combine & check coverage |
| 278 | + needs: [ci-tests, skip-tests, windows-tests] |
| 279 | + if: always() |
| 280 | + runs-on: ubuntu-latest |
| 281 | + |
| 282 | + steps: |
| 283 | + - uses: actions/checkout@v5 |
| 284 | + |
| 285 | + - name: Install uv |
| 286 | + uses: astral-sh/setup-uv@v6 |
| 287 | + with: |
| 288 | + enable-cache: true |
| 289 | + cache-dependency-glob: '**/pyproject.toml' |
| 290 | + |
| 291 | + - uses: actions/download-artifact@v4 |
| 292 | + with: |
| 293 | + pattern: coverage-data-* |
| 294 | + merge-multiple: true |
| 295 | + |
| 296 | + - name: Require 100% Coverage |
| 297 | + id: coverage |
191 | 298 | run: | |
192 | | - echo ${{ github.event_name }} |
| 299 | + uv tool install 'coverage[toml]' |
193 | 300 |
|
194 | | - - name: Upload coverage to Codecov |
195 | | - uses: codecov/codecov-action@v5 |
| 301 | + coverage combine |
| 302 | + coverage html --skip-covered --skip-empty |
| 303 | +
|
| 304 | + # Report and write to summary. |
| 305 | + coverage report --format=markdown >> "$GITHUB_STEP_SUMMARY" |
| 306 | +
|
| 307 | + # Report again and fail if under 100%. |
| 308 | + coverage report --fail-under=100 |
| 309 | +
|
| 310 | + - name: Upload HTML report if check failed |
| 311 | + uses: actions/upload-artifact@v4 |
196 | 312 | with: |
197 | | - fail_ci_if_error: true |
198 | | - token: ${{ secrets.CODECOV_TOKEN }} |
199 | | - if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }} |
| 313 | + name: html-report |
| 314 | + path: htmlcov |
| 315 | + if: ${{ failure() }} |
200 | 316 |
|
201 | | - completion-ci: |
202 | | - needs: build |
| 317 | + # Final completion check |
| 318 | + completion: |
| 319 | + needs: [ci-tests, skip-tests, windows-tests, coverage] |
203 | 320 | runs-on: ubuntu-latest |
204 | | - if: always() # Run even if one matrix job fails |
| 321 | + if: always() |
205 | 322 | steps: |
206 | | - - name: Check matrix job status |
| 323 | + - name: Check all jobs status |
207 | 324 | run: |- |
208 | | - if ! ${{ needs.build.result == 'success' }}; then |
209 | | - echo "One or more matrix jobs failed" |
| 325 | + if ! ${{ needs.ci-tests.result == 'success' }}; then |
| 326 | + echo "CI tests failed" |
| 327 | + exit 1 |
| 328 | + fi |
| 329 | + if ! ${{ needs.skip-tests.result == 'success' }}; then |
| 330 | + echo "Skip tests failed" |
| 331 | + exit 1 |
| 332 | + fi |
| 333 | + if ! ${{ needs.windows-tests.result == 'success' }}; then |
| 334 | + echo "Windows tests failed" |
| 335 | + exit 1 |
| 336 | + fi |
| 337 | + if ! ${{ needs.coverage.result == 'success' }}; then |
| 338 | + echo "Coverage check failed" |
210 | 339 | exit 1 |
211 | 340 | fi |
0 commit comments