Skip to content

Commit 85d691f

Browse files
committed
unbork our coverage setup
there are a couple of problems with our coverage setup: 1. the tox envs generate and attempt to merge coverage files, leading to race conditions. 2. after tox has run, the `tox` make target and the `test` workflow both _also_ try to process the coverage data. 3. the `test` workflow uploads a report to Codecov for each permutation of the python-django-matrix. this is not only inefficient, but also distorts our coverage ratings. at Codecov we're currently scoring 91% coverage, although it should be 93%. this is caused by not properly merging the coverage results of the test matrix and instead uploading them individually, causing our coverage score to be that of the last permutation to finish. 4. for some unexplained reason, usage of the `codecov/codecov-action` was replaced with Codecov's bash importer in fbd0cb1. at that point in time the bash importer had already been deprecated for 18 months (!) and the related repository had already been archived for 8 months. users are officially encouraged to migrate to a newer importer (as implemented in the previously used action). problems 1-3 are addressed by implementing separation of concerns: test runs (whether in workflows or from make targets) now only emit partial coverage data files. combining them and generating reports is done afterward. to address problem 4 the previously used `codecov/codecov-action` action is reinstated and properly configured. finally, re-enable parallel tox runs for the `tox` make target. this was temporarily disabled to circumvent problems 1 and 2 in 7e92f08.
1 parent c3378f5 commit 85d691f

File tree

3 files changed

+74
-16
lines changed

3 files changed

+74
-16
lines changed

.github/workflows/pythonapp.yml

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test
1+
name: CI
22

33
on:
44
push:
@@ -9,8 +9,9 @@ on:
99
- cron: '0 8 * * *'
1010

1111
jobs:
12+
1213
test:
13-
name: 'Python ${{ matrix.python-version }} Django ${{ matrix.django-version }}'
14+
name: 'Test: Python ${{ matrix.python-version }} Django ${{ matrix.django-version }}'
1415
runs-on: ubuntu-latest
1516
strategy:
1617
fail-fast: false
@@ -23,6 +24,7 @@ jobs:
2324
env:
2425
PYTHONUNBUFFERED: 1
2526
PYTHONWARNINGS: always
27+
COVERAGE_FILE: coverage # note: not .coverage: https://github.com/actions/upload-artifact/issues/447
2628
steps:
2729
- name: Checkout
2830
run: |
@@ -32,7 +34,7 @@ jobs:
3234
git checkout $GITHUB_SHA || (git fetch && git checkout $GITHUB_SHA)
3335
3436
- name: 'Set up Python ${{ matrix.python-version }}'
35-
uses: actions/setup-python@v4
37+
uses: actions/setup-python@v5
3638
# https://github.com/marketplace/actions/setup-python
3739
with:
3840
python-version: '${{ matrix.python-version }}'
@@ -57,8 +59,64 @@ jobs:
5759
- name: 'Install Browsers for Playwright tests'
5860
run: make playwright-install
5961

60-
- name: 'Run tests with Python ${{ matrix.python-version }} Django ${{ matrix.django-version }}'
62+
- name: 'Run tests with Python ${{ matrix.python-version }} + Django ${{ matrix.django-version }}'
6163
run: poetry run tox -e $(echo py${{ matrix.python-version }}-django${{ matrix.django-version }} | tr -d .)
6264

63-
- name: 'Upload coverage report'
64-
run: bash <(curl -s https://codecov.io/bash)
65+
- name: Store partial coverage data
66+
uses: actions/upload-artifact@v4
67+
with:
68+
name: coverage-data-py${{ matrix.python-version }}-dj${{ matrix.django-version }}
69+
path: "coverage.*" # note: not .coverage: https://github.com/actions/upload-artifact/issues/447
70+
if-no-files-found: error
71+
# crash if no files for upload could be found.
72+
# the most likely reasons for that are an error with the coverage tool itself
73+
# or a disparity between configured tox envs and the action's matrix.
74+
75+
coverage:
76+
name: Coverage report
77+
runs-on: ubuntu-latest
78+
needs: test
79+
env:
80+
COVERAGE_FILE: coverage # note: not .coverage: https://github.com/actions/upload-artifact/issues/447
81+
steps:
82+
- name: Checkout
83+
uses: actions/checkout@v4
84+
85+
- name: Setup Python
86+
uses: actions/setup-python@v5
87+
with:
88+
python-version: "3.11"
89+
90+
- name: Install coverage
91+
run: python -m pip install --upgrade coverage[toml]
92+
93+
- name: Download partial coverage data
94+
uses: actions/download-artifact@v4
95+
with:
96+
pattern: coverage-data-*
97+
merge-multiple: true
98+
99+
- name: Combine individual data files
100+
run: python -m coverage combine
101+
102+
- name: Print report
103+
run: python -m coverage report
104+
105+
- name: Generate HTML report
106+
run: python -m coverage html
107+
108+
- name: Upload HTML report artifact
109+
uses: actions/upload-artifact@v4
110+
with:
111+
name: coverage-html-report
112+
path: "htmlcov/*"
113+
if-no-files-found: error
114+
115+
- name: Upload report to Codecov
116+
uses: codecov/codecov-action@v3
117+
env:
118+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
119+
with:
120+
files: ${{ env.COVERAGE_FILE }}
121+
fail_ci_if_error: true
122+
verbose: True

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ update: check-poetry ## Update the dependencies as according to the pyproject.to
3333
poetry update -v
3434
poetry install
3535

36+
clear-partial-coverage:
37+
rm -f .coverage.*
38+
3639
lint: ## Run code formatters and linter
3740
poetry run darker --diff --check
3841
poetry run isort --check-only .
@@ -45,18 +48,18 @@ fix-code-style: ## Fix code formatting
4548
tox-listenvs: check-poetry ## List all tox test environments
4649
poetry run tox --listenvs
4750

48-
tox: check-poetry ## Run unittests via tox with all environments
49-
poetry run tox
50-
poetry run coverage combine --append
51+
tox: check-poetry clear-partial-coverage ## Run unittests via tox with all environments
52+
poetry run tox p
53+
poetry run coverage combine
5154
poetry run coverage html
5255
poetry run coverage report
5356

5457
test: check-poetry ## Run unittests
5558
RAISE_LOG_OUTPUT=1 ./manage.sh test --parallel --shuffle --buffer
5659

57-
coverage_test: ## Run tests and generate coverage html report
58-
poetry run coverage run --rcfile=pyproject.toml manage.py test --parallel --shuffle
59-
poetry run coverage combine --append
60+
coverage_test: clear-partial-coverage ## Run tests and generate coverage html report
61+
poetry run coverage run --parallel-mode manage.py test --parallel --shuffle
62+
poetry run coverage combine
6063
poetry run coverage html
6164
poetry run coverage report
6265

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ deps =
140140
commands_pre =
141141
{envpython} -m playwright install chromium firefox
142142
commands =
143-
{envpython} -m coverage run --context='{envname}'
144-
{envpython} -m coverage combine --append
145-
{envpython} -m coverage xml
146-
{envpython} -m coverage report
143+
{envpython} -m coverage run --parallel-mode --context='{envname}'
147144
"""
148145

149146

0 commit comments

Comments
 (0)