-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Implement code coverage in GitHub actions #6441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
# evaluating GitHub actions for CI, disconsider failures when evaluating PRs | ||
# evaluating GitHub actions for CI, disregard failures when evaluating PRs | ||
# | ||
# this is still missing: | ||
# - deploy | ||
# - coverage | ||
# - upload github notes | ||
# | ||
name: main | ||
|
@@ -17,7 +16,6 @@ on: | |
|
||
jobs: | ||
build: | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
|
@@ -86,6 +84,8 @@ jobs: | |
python: "3.7" | ||
os: ubuntu-latest | ||
tox_env: "py37-freeze" | ||
# coverage does not apply for freeze test, skip it | ||
skip_coverage: true | ||
- name: "ubuntu-py38" | ||
python: "3.8" | ||
os: ubuntu-latest | ||
|
@@ -94,6 +94,8 @@ jobs: | |
python: "pypy3" | ||
os: ubuntu-latest | ||
tox_env: "pypy3-xdist" | ||
# coverage too slow with pypy3, skip it | ||
skip_coverage: true | ||
|
||
- name: "macos-py37" | ||
python: "3.7" | ||
|
@@ -118,6 +120,37 @@ jobs: | |
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install tox | ||
- name: Test | ||
run: tox -e ${{ matrix.tox_env }} | ||
pip install tox coverage | ||
|
||
- name: Test without coverage | ||
if: "matrix.skip_coverage" | ||
run: "tox -e ${{ matrix.tox_env }}" | ||
|
||
- name: Test with coverage | ||
if: "! matrix.skip_coverage" | ||
env: | ||
_PYTEST_TOX_COVERAGE_RUN: "coverage run -m" | ||
COVERAGE_PROCESS_START: ".coveragerc" | ||
_PYTEST_TOX_EXTRA_DEP: "coverage-enable-subprocess" | ||
run: "tox -e ${{ matrix.tox_env }}" | ||
|
||
- name: Prepare coverage token | ||
if: success() && !matrix.skip_coverage && ( github.repository == 'pytest-dev/pytest' || github.event_name == 'pull_request' ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hugovk small difference here: we still upload coverage on PRs. Of course this may happen on PRs on fork -> fork, but this should be rare and not a problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, should be fine. So, when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't check, but I think so |
||
run: | | ||
python scripts/append_codecov_token.py | ||
|
||
- name: Combine coverage | ||
if: success() && !matrix.skip_coverage | ||
run: | | ||
python -m coverage combine | ||
python -m coverage xml | ||
|
||
- name: Codecov upload | ||
if: success() && !matrix.skip_coverage | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
token: ${{ secrets.codecov }} | ||
file: ./coverage.xml | ||
flags: ${{ runner.os }} | ||
fail_ci_if_error: false | ||
name: ${{ matrix.name }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Appends the codecov token to the 'codecov.yml' file at the root of the repository. | ||
|
||
This is done by CI during PRs and builds on the pytest-dev repository so we can upload coverage, at least | ||
until codecov grows some native integration like it has with Travis and AppVeyor. | ||
|
||
See discussion in https://github.com/pytest-dev/pytest/pull/6441 for more information. | ||
""" | ||
import os.path | ||
from textwrap import dedent | ||
|
||
|
||
def main(): | ||
this_dir = os.path.dirname(__file__) | ||
cov_file = os.path.join(this_dir, "..", "codecov.yml") | ||
|
||
assert os.path.isfile(cov_file), "{cov_file} does not exist".format( | ||
cov_file=cov_file | ||
) | ||
|
||
with open(cov_file, "a") as f: | ||
# token from: https://codecov.io/gh/pytest-dev/pytest/settings | ||
# use same URL to regenerate it if needed | ||
text = dedent( | ||
""" | ||
codecov: | ||
token: "1eca3b1f-31a2-4fb8-a8c3-138b441b50a7" | ||
""" | ||
) | ||
f.write(text) | ||
|
||
print("Token updated:", cov_file) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ / https://github.com/marketplace/actions/pypi-publish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the links!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ping me for help/review. I'm kinda developing my own framework for GH Apps&Actions + I authored that guide & action...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do! I don't expect many problems, I've already setup deployment for a number of projects (including
pytest-mock
), but you never know!