Skip to content

Commit f4cec1b

Browse files
committed
feat(ci): report coverage from a separate job
1 parent df97845 commit f4cec1b

3 files changed

Lines changed: 79 additions & 20 deletions

File tree

‎.github/workflows/ci-test-conda.yaml‎

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ on:
7373
description: Python version whose leg uploads the coverage report. It must be one of python-versions.
7474
type: string
7575
default: "3.14"
76+
coverage-flag:
77+
description: >-
78+
Name for this coverage report. When set, it is uploaded as a named
79+
parallel build and the caller must close it with ci-coveralls-finish.
80+
Leave empty for a single, self-contained report.
81+
type: string
82+
default: ""
7683
timeout-minutes:
7784
description: Timeout for each job.
7885
type: number
@@ -93,6 +100,8 @@ jobs:
93100
defaults:
94101
run:
95102
shell: bash -el {0}
103+
env:
104+
COVERAGE_LEG: ${{ inputs.coverage && matrix.python-version == inputs.coverage-python-version && matrix.os == fromJSON(inputs.os)[0] }}
96105
strategy:
97106
fail-fast: false
98107
matrix:
@@ -154,27 +163,24 @@ jobs:
154163
TEST_PATH: ${{ inputs.test-path }}
155164
PYTEST_ARGS: ${{ inputs.pytest-args }}
156165
PRE_TEST_COMMAND: ${{ inputs.pre-test-command }}
157-
COVERAGE: ${{ inputs.coverage }}
158166
run: |
159167
if [ -n "${PRE_TEST_COMMAND}" ]; then
160168
eval "${PRE_TEST_COMMAND}"
161169
fi
162170
163171
read -r -a extra_args <<< "${PYTEST_ARGS}"
164172
cov_args=()
165-
if [ "${COVERAGE}" = "true" ]; then
173+
if [ "${COVERAGE_LEG}" = "true" ]; then
166174
cov_args=(--cov "${PACKAGE}" --cov-report term-missing --cov-report "xml:${GITHUB_WORKSPACE}/coverage.xml")
167175
fi
168176
python -m pytest "${extra_args[@]}" "${cov_args[@]}" "${TEST_PATH}"
169177
170-
- name: Upload coverage to Coveralls
171-
if: inputs.coverage && matrix.python-version == inputs.coverage-python-version && matrix.os == fromJSON(inputs.os)[0]
172-
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
178+
- name: Save the coverage report
179+
if: env.COVERAGE_LEG == 'true'
180+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
173181
with:
174-
github-token: ${{ github.token }}
175-
file: ${{ github.workspace }}/coverage.xml
176-
format: cobertura
177-
fail-on-error: false
182+
name: coverage-${{ inputs.package }}
183+
path: ${{ github.workspace }}/coverage.xml
178184

179185
- name: Install the lowest dependencies
180186
if: inputs.lowest-dependencies-check
@@ -203,3 +209,30 @@ jobs:
203209
204210
read -r -a extra_args <<< "${PYTEST_ARGS}"
205211
python -m pytest "${extra_args[@]}" "${TEST_PATH}"
212+
213+
coverage:
214+
name: Coverage
215+
if: inputs.coverage
216+
needs: test
217+
runs-on: ubuntu-26.04
218+
timeout-minutes: 10
219+
permissions:
220+
contents: read
221+
checks: write
222+
statuses: write
223+
224+
steps:
225+
- name: Get the coverage report
226+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
227+
with:
228+
name: coverage-${{ inputs.package }}
229+
230+
- name: Upload coverage to Coveralls
231+
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
232+
with:
233+
github-token: ${{ github.token }}
234+
file: coverage.xml
235+
format: cobertura
236+
flag-name: ${{ inputs.coverage-flag }}
237+
parallel: ${{ inputs.coverage-flag != '' }}
238+
fail-on-error: false

‎.github/workflows/ci-test-python.yaml‎

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ jobs:
7272
defaults:
7373
run:
7474
shell: bash
75+
env:
76+
COVERAGE_LEG: ${{ inputs.coverage && matrix.python-version == inputs.coverage-python-version && matrix.os == fromJSON(inputs.os)[0] }}
7577
strategy:
7678
fail-fast: false
7779
matrix:
@@ -101,27 +103,23 @@ jobs:
101103
PACKAGE: ${{ inputs.package }}
102104
TEST_PATH: ${{ inputs.test-path }}
103105
PRE_TEST_COMMAND: ${{ inputs.pre-test-command }}
104-
COVERAGE: ${{ inputs.coverage }}
105106
run: |
106107
if [ -n "${PRE_TEST_COMMAND}" ]; then
107108
eval "${PRE_TEST_COMMAND}"
108109
fi
109110
110111
cov_args=()
111-
if [ "${COVERAGE}" = "true" ]; then
112+
if [ "${COVERAGE_LEG}" = "true" ]; then
112113
cov_args=(--cov "${PACKAGE}" --cov-report term-missing --cov-report xml)
113114
fi
114115
python -m pytest "${cov_args[@]}" "${TEST_PATH}"
115116
116-
- name: Upload coverage to Coveralls
117-
if: inputs.coverage && matrix.python-version == inputs.coverage-python-version && matrix.os == fromJSON(inputs.os)[0]
118-
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
117+
- name: Save the coverage report
118+
if: env.COVERAGE_LEG == 'true'
119+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
119120
with:
120-
github-token: ${{ github.token }}
121-
file: coverage.xml
122-
flag-name: ${{ inputs.coverage-flag }}
123-
parallel: ${{ inputs.coverage-flag != '' }}
124-
fail-on-error: false
121+
name: coverage-${{ inputs.package }}
122+
path: coverage.xml
125123

126124
- name: Install the lowest dependencies
127125
if: inputs.lowest-dependencies-check
@@ -142,3 +140,29 @@ jobs:
142140
fi
143141
144142
python -m pytest "${TEST_PATH}"
143+
144+
coverage:
145+
name: Coverage
146+
if: inputs.coverage
147+
needs: test
148+
runs-on: ubuntu-26.04
149+
timeout-minutes: 10
150+
permissions:
151+
contents: read
152+
checks: write
153+
statuses: write
154+
155+
steps:
156+
- name: Get the coverage report
157+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
158+
with:
159+
name: coverage-${{ inputs.package }}
160+
161+
- name: Upload coverage to Coveralls
162+
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
163+
with:
164+
github-token: ${{ github.token }}
165+
file: coverage.xml
166+
flag-name: ${{ inputs.coverage-flag }}
167+
parallel: ${{ inputs.coverage-flag != '' }}
168+
fail-on-error: false

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Callers pin a full commit SHA with the version in a trailing comment, so Renovat
6262

6363
| Workflow | Purpose | Caller provides |
6464
|---|---|---|
65-
| `ci-test-python` | Run pytest on a Python and OS matrix, upload coverage, and optionally re-run the tests at the lowest versions that `pyproject.toml` allows (`lowest-dependencies-check`) | `package`, and `checks` and `statuses` write |
65+
| `ci-test-python` | Run pytest on a Python and OS matrix, report coverage to Coveralls in a separate `Coverage` job, and optionally re-run the tests at the lowest versions that `pyproject.toml` allows (`lowest-dependencies-check`) | `package`, and `checks` and `statuses` write |
6666
| `ci-test-conda` | The same for conda-based setups such as AiiDA plugins | `package`, `conda-packages`, and `checks` and `statuses` write |
6767
| `ci-docs` | Build Sphinx docs with warnings as errors | Nothing required |
6868
| `ci-pre-commit` | Run all pre-commit hooks | Nothing required |
@@ -74,6 +74,8 @@ Callers pin a full commit SHA with the version in a trailing comment, so Renovat
7474
| `release-conda` | Build from the release tag and upload to Anaconda.org | `tag` and `ANACONDA_TOKEN` |
7575
| `maintenance-license-year` | Open a pull request that updates the license year | `contents` and `pull-requests` write |
7676

77+
Coverage is measured on one leg only, the first runner in `os` on `coverage-python-version`. That leg saves `coverage.xml` as an artifact, and the `Coverage` job uploads it to Coveralls, so the other legs run without the coverage overhead.
78+
7779
The `actions/cpp-coverage-upload` composite action turns gcov data into an lcov report and uploads it to Coveralls as a named parallel build, so C++ coverage combines with Python coverage. `ci-test-python` and `ci-test-conda` take `pre-test-command`, and `ci-docs` takes `pre-build-command`, for steps that must run first, such as downloading data or generating files. The release workflows also take `dry-run`, which runs every step except the ones that publish or change the repository.
7880

7981
Workflows in this repository are audited with `zizmor` through pre-commit, which runs in CI through `ci-pre-commit`.

0 commit comments

Comments
 (0)