-
-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
Actions workflow to auto-remove unnecessary entries from .coveragerc #113914
base: dev
Are you sure you want to change the base?
Conversation
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.
Would it be possible to extend the CI to automatically check for it on both (partial and full) runs?
As we already create the coverage reports in the CI, I think we only need to parse them at the end
Wouldn't checking in the CI making it cause the tests to run again? (Since these files are ignored in coverage calculation). Or you'd need another way to filter out these files from the generated coverage report |
True that... completely forgotten about it... Not sure if it works but could we disable the |
Ok, so I had originally envisaged this being something that someone would do once in a while e.g. every 6 months, then just create a PR But I do agree that the coverage.xml produced by the CI is tantalisingly close to implementing coveragerc checking/trimming per build. Firstly, we should be sure of where we are heading. Are we saying we'd fail a build if something was in .coveragerc that didn't need to be? If not, then what would the actionable output be and who would know to look at it? In any case, a possible route for that would be:
Some things complicate this approach though:
Overall, I am not convinced there is enough to gain by doing all this. |
script/check_coveragerc.py
Outdated
out_list = [] | ||
for filename, file_data in data["files"].items(): | ||
percent = file_data["summary"]["percent_covered"] | ||
if percent == 100.0: |
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.
When I did a similar thing in the past, we used a lower threshold.
I think we used 90% or maybe even 80%
The idea behind that was that if it was already at say 80%, then we should leverage coverage to warn on coverage reductions.
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 think it makes sense to remove them every once in a while. I think it's also a task for the reviewer to keep an eye out on what's added and what's removed. For example, a One thing that I would think is easy to forget is say, I add tests for a sensor.py (test_sensor.py), but my sensor.py is in the .coveragerc file. Since the .coveragerc isn't touched as a reviewer I probably forget it's there. |
And maybe this can just be a GitHub action that runs once every week at Sunday night or something like that |
5ace68a
to
43088f3
Compare
I'm being picky here...
Edit: |
Thanks for the reviews. As you may see I've got an auto-pruning workflow running but currently having some trouble with it failing the tests that normally pass. I've been testing a cut down proof of concept here: And trying to run the full thing on my fork here: The full test suite is a beast! So will use [no ci] in future commits to this PR to avoid taking up too many of HA's CI minutes. Also will add the timeouts as a precaution. |
Still lots of problems with the tests - seems like it's failing every other test. If anyone has ideas why this is happening I would value their ideas. I may try turning off parallel testing. |
Ok, I think this is ready now. The pytest problems went away when I switched off parallel testing. I have tested on my fork and it's working ok including generating a PR. Feedback welcome - a key question is whether workflows that generate PRs are allowed. |
git fetch origin dev | ||
git add .coveragerc | ||
git commit -m "Remove unnecessary .coveragerc entries" | ||
git push --force --set-upstream origin ${{ env.BRANCH_NAME }} |
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.
Do we really need to make a force push here?
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.
Effectively this is aiming to delete the existing prune_coveragerc_1
branch and replace it with a newly generated one. I didn't want to deal with any merge conflicts. If there were any, I expect the best action would be to fetch, reset, re-run and force push anyway. By not deleting the branch it means any existing PR is retained.
TBH I'm not fully sure what happens with github if you delete a PR's branch then create a new branch with the exact same name.
.github/workflows/ci.yaml
Outdated
@@ -31,6 +31,12 @@ on: | |||
description: "Only run mypy" | |||
default: false | |||
type: boolean | |||
workflow_call: |
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.
Will the workflow_call run the whole CI or only the base job?
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.
workflow_call
here is just to allow codecov.yml
to use parts of ci.yaml
.
Actually it seems to be pretty intelligent and only runs the dependencies (in this case just 'base').
Example run:
https://github.com/davet2001/home-assistant/actions/runs/8503746102
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.
Scratch that. I think you are right - it looks like it calls everything in the CI. So there are some extras we don't really need e.g. pytest-postgres, lint etc. I can't see a way of stopping this, although the big things seem to be the pytest which I do want. I can't see a way of selectively calling only part of a workflow_call, whilst having a custom trigger.
I suppose I could duplicate only the base job into the new .yml file but that seems not ideal.
If you can see a better approach, please let me know!
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 would duplicate what you need from the ci pipeline. By duplicating, we decouple both.
Another idea would be to create a separate file for the base job and use it in both files. But we need to remember that ci.yml
is the main ci and should run smoothly. If creating a separate file for the base job introduces delays or other problems to the ci.yml, we should duplicate it instead
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.
Ok, done. Now duplicated and fully separated.
5367ee9
to
3bbcb2e
Compare
c038e00
to
0ce890f
Compare
.github/workflows/codecov.yml
Outdated
# - 10.11.2 is the version currently shipped with Synology (as of 11 Oct 2023) | ||
# mysql 8.0.32 does not always behave the same as MariaDB | ||
# and some queries that work on MariaDB do not work on MySQL | ||
MARIADB_VERSIONS: "['mariadb:10.3.32','mariadb:10.6.10','mariadb:10.10.3','mariadb:10.11.2','mysql:8.0.32']" |
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.
Please check if all env variables are required, and if not remove the unused ones.
I expect the at least the db variables can be removed
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.
Done
Proposed change
.coveragerc omits certain files from the pytest code coverage report, but some of these omissions are unnecessary because the omitted file reports as having 100% coverage.
This PR includes a script to check .coveragerc for any lines that can be removed,
Also in the PR is the leaner .coveragerc it generated.The generated leaner .coveragerc will be in a separate PR............
Edit 29/3/2024:
The PR now includes a workflow set to run at 4AM each Monday morning, to automatically do the check and create a PR if an improvement is possible. At present I'm not sure if that type of automation is desirable on the HA project, so feedback welcome.
It's also set up so that it can be triggered manually in GH actions.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: