Enhance check_config script with JSON output and fail on warnings#152575
Conversation
There was a problem hiding this comment.
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the check_config script by adding two new command-line flags: --json for machine-readable JSON output and --fail-on-warnings to make warnings cause non-zero exit codes. These additions enable better automation and CI/CD integration while maintaining backwards compatibility.
Key changes:
- Added JSON output format that provides structured data including error counts, warnings, and component information
- Added option to treat warnings as failures for stricter validation in automated environments
- Enhanced exit code logic to handle the new warning failure mode
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/scripts/check_config.py |
Added argument parsing for new flags, JSON output generation, and modified exit code logic |
tests/scripts/test_check_config.py |
Comprehensive test suite covering new functionality, flag interactions, and edge cases |
bf3ebc8 to
b31b4dd
Compare
|
@kellerza , just wanted to see if you could potentially take a look at this when you get the chance - I notice for this file you are the only one marked as an owner. :) |
kellerza
left a comment
There was a problem hiding this comment.
Very comprehensive tests!
It seems --secrets is not executed as part of --json. Do you want to include / simply print a warning if --secrets is present during --json output?
9faa5cf to
ceeaa6a
Compare
|
@kellerza - to your secrets comment - good catch - and I don't have a use for secrets as part of the json currently so I printed out a comment in that case. (ac532ec) but if it is desirable, we could add it with something like this: But also we could wait until that is actually desired and leave as is for now. Thoughts? |
|
@kellerza need anything else from me to move forward on this? |
That should be best. I don't really want to print out any secret values specifically |
50392e8 to
c43fb7e
Compare
- Add JSON output format support to check_config.py - Implement command-line flags for better script control - Add extensive test coverage for flag interactions and JSON output - Improve argument parsing to properly handle script arguments - Refactor test file for better readability and maintainability - Fix ruff formatting and linting issues
c43fb7e to
2860c69
Compare
check_config script with JSON output and fail on warnings.check_config script with JSON output and fail on warnings.
check_config script with JSON output and fail on warnings.check_config script with JSON output and fail on warnings
|
This should be good to merge. Do you already have a docs PR for the two new command line flags? https://www.home-assistant.io/docs/tools/check_config/ |
frenck
left a comment
There was a problem hiding this comment.
Although I must admit, the use case for this one is slim (not widely adopted probably), the implementation looks solid.
Since it has no impact otherwise, I'm going to add this one in.
Thanks for this fine contribution @BenjaminMichaelis 👍
../Frenck
|
Thanks @BenjaminMichaelis ! |
Proposed change
I run check_config to validate my HA configuration in my CI pipelines.
However, warnings seem to be always treated as non-fatal, missing errors I want to be automatically caught. In addition, there are limited customization options for the validation process.
Type of change
Not totally sure what this falls under since it isn't a full integration, but giving it my best guess :)
Additional information
This pr introduces 2 flags to be able to improve on that without breaking current functionality.
--fail-on-warnings- Provides a non-zero exit code if there are any warnings--json- This provides machine readable output of the result so better customizations can be run against structured outputChecklist
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.To help with the load of incoming pull requests: