Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 2, 2025

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)

  • JSON Schema Validation: Validates all 30 JSON files are syntactically valid and conform to JSON Schema specifications (Draft 7 and Draft 2020-12)
  • YAML Configuration Validation: Validates .infrahub.yml files against the repository configuration schema
  • Comprehensive Error Reporting: Provides detailed error messages with line numbers and context
  • Robust Error Handling: Handles various failure scenarios gracefully

🚀 GitHub Actions Workflow (.github/workflows/validate-schemas.yml)

  • Runs on push/PR to main and develop branches
  • Uses Python 3.11 with required dependencies (jsonschema, PyYAML)
  • Executes validation script with detailed output
  • Double-checks JSON syntax using jq as additional validation layer
  • Fails CI build if any validation errors are detected

📚 Documentation & Maintenance

  • Updated README: Added validation section with local testing instructions
  • Added .gitignore: Comprehensive Python project gitignore to prevent committing temporary files
  • Clear Instructions: Documentation for running validation locally and understanding CI process

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:

🔍 Validating JSON schema files...
  Checking schemas/infrahub/schema/develop.json...
    ✅ Valid JSON schema
  Checking schemas/python-sdk/repository-config/develop.json...
    ✅ Valid JSON schema
  [... 28 more files ...]

📊 Validation Summary:
  JSON files checked: 30
  .infrahub.yml files checked: 0

✅ All files passed validation!

Local Testing

Run validation locally with:

python validate_schemas.py

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.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 2, 2025

Deploying infrahub-schema with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copilot AI changed the title [WIP] Add CI job to validate that all of the json files within this repo are valid json-schema files Add CI job to validate JSON schema files and .infrahub.yml configurations Jul 2, 2025
Copilot AI requested a review from ogenstad July 2, 2025 09:56
run: chmod +x validate_schemas.py

- name: Validate JSON schema files
run: python validate_schemas.py
Copy link
Contributor

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?

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Copilot AI commented Jul 2, 2025

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 addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

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

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?

Copy link
Contributor Author

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.


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):
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copilot AI requested a review from ogenstad July 2, 2025 12:01
@ogenstad ogenstad marked this pull request as ready for review August 27, 2025 11:20
@ogenstad ogenstad merged commit 25c3941 into main Aug 27, 2025
1 check passed
@ogenstad ogenstad deleted the copilot/fix-21 branch August 27, 2025 11:20
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.

Add CI job to validate that all of the json files within this repo are valid json-schema files

2 participants