Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/validate-schemas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Validate JSON Schemas

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
validate-schemas:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: "latest"

- name: Install dependencies
run: |
uv sync --extra dev

- 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.


- name: Check for JSON syntax in all JSON files
run: |
echo "πŸ” Double-checking JSON syntax with jq..."
find . -name "*.json" -type f | while read file; do
echo "Checking $file"
if ! jq empty "$file" 2>/dev/null; then
echo "❌ Invalid JSON in $file"
exit 1
fi
done
echo "βœ… All JSON files have valid syntax"
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Temporary files
/tmp/
*.tmp
*.temp

# Python cache
__pycache__/
*.py[cod]
*$py.class
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
*.manifest
*.spec

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDEs
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@ kind: Menu

Everything under the `schemas/` directory is automatically published to `https://schema.infrahub.app` to simplify the integration with external tools that requires a public URL

## Validation

This repository includes automated validation to ensure all JSON files are valid JSON schemas and any `.infrahub.yml` files conform to the repository configuration schema.

### Running Validation Locally

To validate all schema files locally:

```shell
uv run pytest test_schema_validation.py -v
```

This will:
- Validate that all `.json` files contain valid JSON and are valid JSON schemas
- Validate that any `.infrahub.yml` files are valid YAML and conform to the repository config schema
- Report any validation errors with detailed error messages

### Continuous Integration

The validation runs automatically on every push and pull request via GitHub Actions. The CI workflow:
- Validates all JSON schema files using pytest
- Double-checks JSON syntax using `jq`
- Fails the build if any validation errors are found

## How to update a Schema

Generate the new schemas, using the invoke tool from the main [Infrahub repository](https://github.com/opsmill/infrahub).
Expand All @@ -54,3 +78,9 @@ Example:
cd schemas/infrahub/schema
ln -f -s 0.12.0.json latest.json
```

After updating schemas, run the validation to ensure they are correct:

```shell
uv run pytest test_schema_validation.py -v
```
Loading