Skip to content

Commit 690a906

Browse files
authored
Replace codecov with python-coverage-comment-action (#1649)
1 parent 6e2a698 commit 690a906

File tree

6 files changed

+87
-14
lines changed

6 files changed

+87
-14
lines changed

.github/workflows/coverage.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# .github/workflows/coverage.yml
2+
name: Post coverage comment
3+
4+
on:
5+
workflow_run:
6+
workflows: ["Tests"]
7+
types:
8+
- completed
9+
10+
jobs:
11+
test:
12+
name: Run tests & display coverage
13+
runs-on: ubuntu-latest
14+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
15+
permissions:
16+
# Gives the action the necessary permissions for publishing new
17+
# comments in pull requests.
18+
pull-requests: write
19+
# Gives the action the necessary permissions for editing existing
20+
# comments (to avoid publishing multiple comments in the same PR)
21+
contents: write
22+
# Gives the action the necessary permissions for looking up the
23+
# workflow that launched this workflow, and download the related
24+
# artifact that contains the comment to be published
25+
actions: read
26+
steps:
27+
# DO NOT run actions/checkout here, for security reasons
28+
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
29+
- name: Post comment
30+
uses: py-cov-action/python-coverage-comment-action@v3
31+
with:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}

.github/workflows/tests.yml

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
python -m pip install --upgrade pip setuptools
2727
- name: Install dependencies
2828
run: |
29-
python -m pip install coverage tox tox-py unittest-xml-reporting
29+
python -m pip install coverage[toml] tox tox-py unittest-xml-reporting
3030
- name: Run tox
3131
run: |
3232
python -m pip --version
@@ -35,12 +35,54 @@ jobs:
3535
- name: Coverage reporting
3636
run: |
3737
coverage combine
38-
coverage report -m
39-
coverage xml
40-
coverage html
41-
- name: Publish coverage results
42-
uses: codecov/codecov-action@v4
38+
coverage report --show-missing
39+
mv .coverage .coverage.${{ matrix.python-version }}
40+
- name: Store coverage file
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: coverage-${{ matrix.python-version }}
44+
path: .coverage.${{ matrix.python-version }}
45+
46+
coverage:
47+
name: Coverage
48+
runs-on: ubuntu-latest
49+
needs: tests
50+
permissions:
51+
# If the author is a maintainer, the permission level is set by the
52+
# values below.
53+
# `pull-requests: write` is needed for publishing new comments in pull
54+
# requests.
55+
# `contents: write` is needed for pushing data to the
56+
# `python-coverage-comment-action` branch, and for editing existing
57+
# comments (to avoid publishing multiple comments in the same PR)
58+
# In case the pull request comes from a forked repository, the maximum
59+
# permission level is read, so the permissions below won't be acted upon
60+
# by GitHub.
61+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
62+
pull-requests: write
63+
contents: write
64+
steps:
65+
- uses: actions/checkout@v4
4366

67+
- uses: actions/download-artifact@v4
68+
id: download
69+
with:
70+
pattern: coverage-*
71+
merge-multiple: true
72+
73+
- name: Coverage comment
74+
id: coverage_comment
75+
uses: py-cov-action/python-coverage-comment-action@v3
76+
with:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
MERGE_COVERAGE_FILES: true
79+
80+
- name: Store Pull Request comment to be posted
81+
uses: actions/upload-artifact@v4
82+
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
83+
with:
84+
name: python-coverage-comment-action
85+
path: python-coverage-comment-action.txt
4486

4587
isort:
4688
runs-on: ubuntu-latest

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ add dynamic ``QuerySet`` filtering from URL parameters.
66

77
Full documentation on `read the docs`_.
88

9-
.. image:: https://codecov.io/gh/carltongibson/django-filter/branch/develop/graph/badge.svg
10-
:target: https://codecov.io/gh/carltongibson/django-filter
9+
.. image:: https://raw.githubusercontent.com/carltongibson/django-filter/python-coverage-comment-action-data/badge.svg
10+
:target: https://github.com/carltongibson/django-filter/tree/python-coverage-comment-action-data
1111

1212
.. image:: https://badge.fury.io/py/django-filter.svg
1313
:target: http://badge.fury.io/py/django-filter

codecov.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ known_first_party = ["django_filters"]
5454

5555
[tool.flit.module]
5656
name = "django_filters"
57+
58+
[tool.coverage.run]
59+
relative_files = true

requirements/test-ci.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
markdown
22
django-crispy-forms
33

4-
coverage
4+
coverage[toml]
55
pytz
66
unittest-xml-reporting

0 commit comments

Comments
 (0)