Skip to content

Commit 95a98f1

Browse files
ci: add JSON Schema and validate-config workflow
Add config/schema/variables.schema.json for validating variables.example.yml. Add CI workflow that validates example config against schema on PR. Part of AzureLocal/azurelocal.github.io#15
1 parent 7b6aa51 commit 95a98f1

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# =============================================================================
2+
# validate-config.yml — Validate config/variables.example.yml against schema
3+
# =============================================================================
4+
# Triggered on PRs and pushes that touch config/ or this workflow.
5+
# Validates YAML syntax and JSON Schema compliance.
6+
# =============================================================================
7+
8+
name: Validate Configuration
9+
10+
on:
11+
push:
12+
branches: [main]
13+
paths:
14+
- 'config/**'
15+
- '.github/workflows/validate-config.yml'
16+
pull_request:
17+
branches: [main]
18+
paths:
19+
- 'config/**'
20+
workflow_dispatch:
21+
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
validate:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v4
32+
33+
- name: Setup Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.12'
37+
38+
- name: Install dependencies
39+
run: pip install pyyaml jsonschema
40+
41+
- name: Validate variables.example.yml against schema
42+
run: |
43+
python3 -c "
44+
import yaml, json, sys
45+
from jsonschema import validate, ValidationError
46+
47+
with open('config/variables.example.yml') as f:
48+
data = yaml.safe_load(f)
49+
50+
with open('config/schema/variables.schema.json') as f:
51+
schema = json.load(f)
52+
53+
try:
54+
validate(instance=data, schema=schema)
55+
print('✅ config/variables.example.yml passes schema validation')
56+
except ValidationError as e:
57+
print(f'❌ Schema validation failed: {e.message}')
58+
print(f' Path: {\" > \".join(str(p) for p in e.absolute_path)}')
59+
sys.exit(1)
60+
"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://github.com/AzureLocal/azurelocal-vm-conversion-toolkit/config/schema/variables.schema.json",
4+
"title": "VM Conversion Toolkit Variables",
5+
"description": "Schema for config/variables.example.yml — validates required sections and key structure.",
6+
"type": "object",
7+
"required": ["azure", "azure_local", "conversion", "tags"],
8+
"properties": {
9+
"azure": {
10+
"type": "object",
11+
"required": ["subscription_id", "resource_group", "location"],
12+
"properties": {
13+
"subscription_id": { "type": "string" },
14+
"resource_group": { "type": "string" },
15+
"location": { "type": "string" }
16+
}
17+
},
18+
"azure_local": {
19+
"type": "object",
20+
"required": ["custom_location_id", "logical_network_id"],
21+
"properties": {
22+
"custom_location_id": { "type": "string" },
23+
"logical_network_id": { "type": "string" }
24+
}
25+
},
26+
"conversion": {
27+
"type": "object",
28+
"required": ["working_directory"],
29+
"properties": {
30+
"working_directory": { "type": "string" },
31+
"max_parallel": { "type": "integer", "minimum": 1 }
32+
}
33+
},
34+
"tags": {
35+
"type": "object",
36+
"additionalProperties": { "type": "string" }
37+
}
38+
},
39+
"additionalProperties": false
40+
}

0 commit comments

Comments
 (0)