Skip to content

Commit 49fbd9f

Browse files
committed
Implement code coverage in GitHub actions
This overwrites the `codecov.yml` file in the root of the repository with `codecov-upstream.yml` file (which contains the code-cov token)´, so PRs and branches on the repository can upload coverage. Suggestion from here: #6421 (comment) Security concerns: the token might be misused, but only to upload bogus coverage to `codecov.io`, so the team believe this is harmless. If we decide to fallback from this decision , we just need to revoke the token. Related to #6369
1 parent 622995a commit 49fbd9f

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

.github/codecov-upstream.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# this file replaces <root>/codecov.yml when building on the main repository and PRs
2+
coverage:
3+
status:
4+
project: true
5+
patch: true
6+
changes: true
7+
8+
comment: off
9+
10+
codecov:
11+
# token from: https://codecov.io/gh/pytest-dev/pytest/settings
12+
# use same URL to regenerate it if needed
13+
token: "1eca3b1f-31a2-4fb8-a8c3-138b441b50a7"

.github/workflows/main.yml

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# evaluating GitHub actions for CI, disconsider failures when evaluating PRs
1+
# evaluating GitHub actions for CI, disregard failures when evaluating PRs
22
#
33
# this is still missing:
44
# - deploy
5-
# - coverage
65
# - upload github notes
76
#
87
name: main
@@ -17,6 +16,10 @@ on:
1716

1817
jobs:
1918
build:
19+
env:
20+
_PYTEST_TOX_COVERAGE_RUN: "coverage run -m"
21+
COVERAGE_PROCESS_START: ".coveragerc"
22+
_PYTEST_TOX_EXTRA_DEP: "coverage-enable-subprocess"
2023

2124
runs-on: ${{ matrix.os }}
2225

@@ -86,6 +89,8 @@ jobs:
8689
python: "3.7"
8790
os: ubuntu-latest
8891
tox_env: "py37-freeze"
92+
# coverage does not apply for freeze test, skip it
93+
skip_coverage: true
8994
- name: "ubuntu-py38"
9095
python: "3.8"
9196
os: ubuntu-latest
@@ -94,6 +99,8 @@ jobs:
9499
python: "pypy3"
95100
os: ubuntu-latest
96101
tox_env: "pypy3-xdist"
102+
# coverage too slow with pypy3, skip it
103+
skip_coverage: true
97104

98105
- name: "macos-py37"
99106
python: "3.7"
@@ -118,6 +125,32 @@ jobs:
118125
- name: Install dependencies
119126
run: |
120127
python -m pip install --upgrade pip
121-
pip install tox
128+
pip install tox coverage
122129
- name: Test
123-
run: tox -e ${{ matrix.tox_env }}
130+
shell: bash
131+
run: |
132+
if [[ "${{ matrix.skip_coverage }}" = "true" ]]; then
133+
export _PYTEST_TOX_COVERAGE_RUN=
134+
fi
135+
tox -e ${{ matrix.tox_env }}
136+
137+
- name: Prepare coverage token
138+
if: success() && !matrix.skip_coverage && ( github.repository == 'pytest-dev/pytest' || github.event_name == 'pull_request' )
139+
run: |
140+
cp .github/codecov-upstream.yml codecov.yml
141+
142+
- name: Combine coverage
143+
if: success() && !matrix.skip_coverage
144+
run: |
145+
python -m coverage combine
146+
python -m coverage xml
147+
148+
- name: Codecov upload
149+
if: success() && !matrix.skip_coverage
150+
uses: codecov/codecov-action@v1
151+
with:
152+
token: ${{ secrets.codecov }}
153+
file: ./coverage.xml
154+
flags: ${{ runner.os }}
155+
fail_ci_if_error: false
156+
name: ${{ matrix.name }}

codecov.yml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# note: `.github/codecov-upstream.yml` is basically a copy of this file, please propagate
2+
# changes as needed
13
coverage:
24
status:
35
project: true

0 commit comments

Comments
 (0)