Skip to content

Commit d660537

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 d660537

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
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
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

+38-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ on:
1717

1818
jobs:
1919
build:
20+
env:
21+
_PYTEST_TOX_COVERAGE_RUN: "coverage run -m"
2022

2123
runs-on: ${{ matrix.os }}
2224

@@ -86,6 +88,10 @@ jobs:
8688
python: "3.7"
8789
os: ubuntu-latest
8890
tox_env: "py37-freeze"
91+
# coverage does not apply for freeze test, skip it
92+
skip_coverage: true
93+
env:
94+
_PYTEST_TOX_COVERAGE_RUN:
8995
- name: "ubuntu-py38"
9096
python: "3.8"
9197
os: ubuntu-latest
@@ -94,6 +100,10 @@ jobs:
94100
python: "pypy3"
95101
os: ubuntu-latest
96102
tox_env: "pypy3-xdist"
103+
# coverage too slow with pypy3, skip it
104+
skip_coverage: true
105+
env:
106+
_PYTEST_TOX_COVERAGE_RUN:
97107

98108
- name: "macos-py37"
99109
python: "3.7"
@@ -118,6 +128,32 @@ jobs:
118128
- name: Install dependencies
119129
run: |
120130
python -m pip install --upgrade pip
121-
pip install tox
131+
pip install tox coverage
122132
- name: Test
123-
run: tox -e ${{ matrix.tox_env }}
133+
env:
134+
COVERAGE_PROCESS_START: ".coveragerc"
135+
_PYTEST_TOX_COVERAGE_RUN: "coverage run -m"
136+
_PYTEST_TOX_EXTRA_DEP: "coverage-enable-subprocess"
137+
run: |
138+
tox -e ${{ matrix.tox_env }}
139+
140+
- name: Prepare coverage token
141+
if: success() && !matrix.skip_coverage && ( github.repository == 'pytest-dev/pytest' || github.event_name == 'pull_request' )
142+
run: |
143+
cp .github/codecov-upstream.yml codecov.yml
144+
145+
- name: Combine coverage
146+
if: success() && !matrix.skip_coverage
147+
run: |
148+
python -m coverage combine
149+
python -m coverage xml
150+
151+
- name: Codecov upload
152+
if: success() && !matrix.skip_coverage
153+
uses: codecov/codecov-action@v1
154+
with:
155+
token: ${{ secrets.codecov }}
156+
file: ./coverage.xml
157+
flags: ${{ runner.os }}
158+
fail_ci_if_error: false
159+
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)