-
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
Conversation
(converting to draft until I can confirm it works on my fork) |
8d210c5
to
deb32a6
Compare
deb32a6
to
3836efd
Compare
# 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 |
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'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.
- 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 }} |
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.
Usually, I tend to use the COVERAGE_FILE
env var to control the name of the coverage file, but it changes the way coverage combine
works, and I was afraid I'd have to change more things for this to work, so I opted to move myself the .coverage into its own name.
[tool.coverage.run] | ||
relative_files = true |
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.
Because this was added to pyproject.toml
, I had to add the extra [toml]
in the placeS where coverage
is installed. It wouldn't be the case if we put the coverage
config in a different file, but it feels right to put it here. Feel free to indicate if you'd like it another way.
coverage xml | ||
coverage html |
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.
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 comment
The 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 MINIMUM_GREEN
which by default is 100
(which might be a bit overkill). Your current coverage is 98% (👏) and will appear orange with the default settings.
All good on my fork:
(of course, the badge on the readme fails because it actually points to your fork and not mine, but I double-checked the link) |
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.
@ewjoachim This looks lovely. Big fan of the nice comments 🎁.
Let's give it a run. Thanks!
Fixes #1647
I hope this is the kind of input you had in mind :)
The GHA code is mainly taken from the action's readme doc.
I'll merge it on my fork to check that it runs as expected.
Thanks for the kind nudge!