-
Notifications
You must be signed in to change notification settings - Fork 1
Add CI job to validate JSON schema files and .infrahub.yml configurations #22
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
Conversation
Deploying infrahub-schema with
|
| Latest commit: |
0cbe00f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://596c6994.infrahub-schema.pages.dev |
| Branch Preview URL: | https://copilot-fix-21.infrahub-schema.pages.dev |
Co-authored-by: ogenstad <[email protected]>
| run: chmod +x validate_schemas.py | ||
|
|
||
| - name: Validate JSON schema files | ||
| run: python validate_schemas.py |
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.
Can we do this with pytest 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.
Converted to pytest in commit b9c70e5. The validation is now implemented as pytest tests that provide better reporting and can be run with poetry run pytest test_schema_validation.py -v.
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install jsonschema PyYAML |
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.
Instead of installing packages like this can we manage develop dependencies within pyproject.toml instead? Currently the repo is setup to use poetry but we can go ahead and change that to uv instead as that part of the repo isn't currently in use.
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.
Updated in commit b9c70e5. Dependencies are now managed in pyproject.toml under [tool.poetry.group.dev.dependencies] and the workflow uses poetry install --with dev to install them.
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.
Can we use uv instead of poetry?
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.
Switched to uv for dependency management in commit f741199. The workflow now uses uv sync --extra dev and uv run pytest instead of poetry commands. Also simplified pyproject.toml to use standard Python project format and replaced poetry.lock with uv.lock.
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: '3.11' |
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 use Python 3.12.
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.
Updated to Python 3.12 in commit b9c70e5. Also updated the Python version constraint in pyproject.toml to ^3.9, < 3.13 to support Python 3.12.
Co-authored-by: ogenstad <[email protected]>
Co-authored-by: ogenstad <[email protected]>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
|
||
| - name: Validate JSON schema files with pytest | ||
| run: | | ||
| uv run pytest test_schema_validation.py -v |
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.
Can you move test_schema_validation.py to a tests directory and instead only run pytest -v here without specifying the file?
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.
Moved the test file to tests directory and updated the workflow to run pytest -v without specifying the file in commit 0cbe00f.
test_schema_validation.py
Outdated
|
|
||
| print(f"✅ All {len(json_files)} JSON files passed validation!") | ||
|
|
||
| def test_collect_and_validate_all_infrahub_yml_files(self, infrahub_yml_files, repository_config_schema_path): |
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.
Even though yml files were mentioned in the issue as we don't have any defined can we instead remove this part for now so that we only validate that the json files themselves are correct?
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.
Removed all YAML validation functionality and PyYAML dependency since there are no .infrahub.yml files in the repository. Now only validates JSON files for correct syntax and schema compliance in commit 0cbe00f.
Co-authored-by: ogenstad <[email protected]>
This PR adds comprehensive validation for all JSON schema files and .infrahub.yml configuration files in the repository through automated CI checks.
Changes Made
🔧 Validation Script (
validate_schemas.py).infrahub.ymlfiles against the repository configuration schema🚀 GitHub Actions Workflow (
.github/workflows/validate-schemas.yml)mainanddevelopbranchesjsonschema,PyYAML)jqas additional validation layer📚 Documentation & Maintenance
Validation Results
✅ All 30 existing JSON schema files pass validation
✅ Proper error detection for invalid JSON syntax
✅ Proper error detection for invalid JSON schemas
✅ YAML validation against repository config schema works correctly
Example validation output:
Local Testing
Run validation locally with:
This provides the same comprehensive validation that runs in CI, ensuring schema integrity before committing changes.
Fixes #21.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.