Skip to content
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

Generate coverage reports using only GitHub Actions, without codecov.io #447

Merged
merged 17 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,20 @@ jobs:

- run: nox --python ${{ matrix.python.action }} -e ${{ matrix.task.nox }} -- --use-wheel dist/*.whl

- name: Store coverage file
uses: actions/upload-artifact@v3
with:
# We have a single artifact shared for each workflow run.
# in this way we should intefere with coverage reports from other PRs
# or previous runs for the same PR.
name: coverage-${{ github.run_id }}
# Is important to keep the unique names for the coverage files
# so that when uploaded to the same artifact, they don't overlap.
path: .coverage.*

- name: Codecov
run: |
coverage combine
codecov -n "GitHub Actions - ${{ matrix.task.name}} - ${{ matrix.os.name }} ${{ matrix.python.name }}"


Expand Down Expand Up @@ -232,6 +244,37 @@ jobs:
password: ${{ secrets.PYPI_TOKEN }}
verbose: true

coverage-report:
name: Coverage report
runs-on: ubuntu-latest
needs:
# We are waiting only for test jobs.
- test-linux
- test-windows
steps:
- uses: actions/checkout@v3
adiroiban marked this conversation as resolved.
Show resolved Hide resolved

- name: Install dependencies
run: python -m pip install --upgrade pip coverage[toml] diff_cover
adiroiban marked this conversation as resolved.
Show resolved Hide resolved

- name: Download coverage reports
uses: actions/download-artifact@v3
with:
name: coverage-${{ github.run_id }}
path: .

- name: Combine coverage
run: coverage combine

- name: Report coverage
run: coverage report
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also create an html report and artifact it for download?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My plan is to send the diff coverage report as a comment... downloading the artifact looks complicated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's wouldn't be a primary use. But, it is how you can you get a nice view of the code and coverage without having somewhere to upload the html. Anyways, not critical, just a thought that can also be easily added later.


- name: Diff coverage
run: |
coverage xml
diff-cover --fail-under=100 coverage.xml


# This is a meta-job to simplify PR CI enforcement configuration in GitHub.
# Inside the GitHub config UI you only configure this job as required.
# All the extra requirements are defined "as code" as part of the `needs`
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dist/
venv/
htmlcov/
.coverage
coverage.xml
*~
*.lock
apidocs/
Expand Down
3 changes: 1 addition & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ def tests(session: nox.Session) -> None:
session.run("coverage", "run", "--module", "twisted.trial", *posargs)

if os.environ.get("CI") != "true":
# When running the test localy, show the coverage report.
adiroiban marked this conversation as resolved.
Show resolved Hide resolved
session.notify("coverage_report")
else:
session.run("coverage", "combine")


@nox.session
Expand Down