-
Notifications
You must be signed in to change notification settings - Fork 771
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
Replace codecov with python-coverage-comment-action #1649
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# .github/workflows/coverage.yml | ||
name: Post coverage comment | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Tests"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
test: | ||
name: Run tests & display coverage | ||
runs-on: ubuntu-latest | ||
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' | ||
permissions: | ||
# Gives the action the necessary permissions for publishing new | ||
# comments in pull requests. | ||
pull-requests: write | ||
# Gives the action the necessary permissions for editing existing | ||
# comments (to avoid publishing multiple comments in the same PR) | ||
contents: write | ||
# Gives the action the necessary permissions for looking up the | ||
# workflow that launched this workflow, and download the related | ||
# artifact that contains the comment to be published | ||
actions: read | ||
steps: | ||
# DO NOT run actions/checkout here, for security reasons | ||
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | ||
- name: Post comment | ||
uses: py-cov-action/python-coverage-comment-action@v3 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ jobs: | |
python -m pip install --upgrade pip setuptools | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install coverage tox tox-py unittest-xml-reporting | ||
python -m pip install coverage[toml] tox tox-py unittest-xml-reporting | ||
- name: Run tox | ||
run: | | ||
python -m pip --version | ||
|
@@ -35,12 +35,54 @@ jobs: | |
- name: Coverage reporting | ||
run: | | ||
coverage combine | ||
coverage report -m | ||
coverage xml | ||
coverage html | ||
- name: Publish coverage results | ||
uses: codecov/codecov-action@v4 | ||
coverage report --show-missing | ||
mv .coverage .coverage.${{ matrix.python-version }} | ||
Comment on lines
35
to
+39
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. Usually, I tend to use the |
||
- name: Store coverage file | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-${{ matrix.python-version }} | ||
path: .coverage.${{ matrix.python-version }} | ||
|
||
coverage: | ||
name: Coverage | ||
runs-on: ubuntu-latest | ||
needs: tests | ||
permissions: | ||
# If the author is a maintainer, the permission level is set by the | ||
# values below. | ||
# `pull-requests: write` is needed for publishing new comments in pull | ||
# requests. | ||
# `contents: write` is needed for pushing data to the | ||
# `python-coverage-comment-action` branch, and for editing existing | ||
# comments (to avoid publishing multiple comments in the same PR) | ||
# In case the pull request comes from a forked repository, the maximum | ||
# permission level is read, so the permissions below won't be acted upon | ||
# by GitHub. | ||
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token | ||
Comment on lines
+51
to
+61
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. I've tried being a bit verbose because it's important that readers understand the security implications on those lines. If you prefer without the comments or with less comments, let me know. |
||
pull-requests: write | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/download-artifact@v4 | ||
id: download | ||
with: | ||
pattern: coverage-* | ||
merge-multiple: true | ||
|
||
- name: Coverage comment | ||
id: coverage_comment | ||
uses: py-cov-action/python-coverage-comment-action@v3 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
MERGE_COVERAGE_FILES: true | ||
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. I haven't changed the action settings more than necessary. In particular, if you want your badge to appear green, you'll have to tweak |
||
|
||
- name: Store Pull Request comment to be posted | ||
uses: actions/upload-artifact@v4 | ||
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' | ||
with: | ||
name: python-coverage-comment-action | ||
path: python-coverage-comment-action.txt | ||
|
||
isort: | ||
runs-on: ubuntu-latest | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,6 @@ known_first_party = ["django_filters"] | |
|
||
[tool.flit.module] | ||
name = "django_filters" | ||
|
||
[tool.coverage.run] | ||
relative_files = true | ||
Comment on lines
+58
to
+59
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. Because this was added to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
markdown | ||
django-crispy-forms | ||
|
||
coverage | ||
coverage[toml] | ||
pytz | ||
unittest-xml-reporting |
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.
I'm not sure I understand why coverage xml and html files were produced. xml, I'd guess it's because codecov needs it (though I would have thought it used the .coverage file itself).
.html, I really have no idea. Of course, if this serves a purpose that I didn't see, please tell me, I'll be delighted to re-add it with a comment to explain why.
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.
This was a legacy thing. (Don't ask 😅) Fine to get rid of it.