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

Replace codecov with python-coverage-comment-action #1649

Merged
merged 1 commit into from
Mar 17, 2024

Conversation

ewjoachim
Copy link
Contributor

Fixes #1647

@carltongibson said:
@ewjoachim Input always welcomed 😜
-- #1647 (comment)

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!

@ewjoachim ewjoachim marked this pull request as draft March 17, 2024 00:12
@ewjoachim
Copy link
Contributor Author

(converting to draft until I can confirm it works on my fork)

@ewjoachim ewjoachim force-pushed the py-cov-action branch 2 times, most recently from 8d210c5 to deb32a6 Compare March 17, 2024 00:27
Comment on lines +51 to +61
# 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
Copy link
Contributor Author

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.

Comment on lines 35 to +39
- 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 }}
Copy link
Contributor Author

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.

Comment on lines +58 to +59
[tool.coverage.run]
relative_files = true
Copy link
Contributor Author

@ewjoachim ewjoachim Mar 17, 2024

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.

Comment on lines -39 to -40
coverage xml
coverage html
Copy link
Contributor Author

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.

Copy link
Owner

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
Copy link
Contributor Author

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.

@ewjoachim
Copy link
Contributor Author

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)

Coverage badge

@ewjoachim ewjoachim marked this pull request as ready for review March 17, 2024 00:53
Copy link
Owner

@carltongibson carltongibson left a 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!

@carltongibson carltongibson merged commit 690a906 into carltongibson:main Mar 17, 2024
9 checks passed
last-partizan pushed a commit to last-partizan/django-filter that referenced this pull request Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch GHA to use py-cov-action / python-coverage-comment-action
2 participants