Skip to content

Commit cf7cf6d

Browse files
jubradclaude
andcommitted
Add schema sync check workflow and documentation
- Add check_schema_sync.py to verify generated types match upstream schemas - Add GitHub Actions workflow to run sync check on PRs - Update CONTRIBUTING.md with instructions for regenerating types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 10d351e commit cf7cf6d

3 files changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check Schema Sync
2+
3+
on:
4+
merge_group:
5+
pull_request:
6+
branches: [main]
7+
workflow_dispatch:
8+
9+
jobs:
10+
check-schema-sync:
11+
name: Verify CRD and Helm Schema Sync
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v4
19+
with:
20+
version: "latest"
21+
22+
- name: Set up Python
23+
run: uv python install 3.12
24+
25+
- name: Install dependencies
26+
run: uv sync
27+
28+
- name: Check schema sync
29+
run: uv run python scripts/check_schema_sync.py --show-fields

CONTRIBUTING.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ Pull requests are the best way to propose changes to the codebase. We actively w
2222
6. Issue that pull request!
2323

2424

25+
## Development Setup
26+
27+
This project uses [uv](https://docs.astral.sh/uv/) for Python dependency management. Install uv first:
28+
29+
```bash
30+
# macOS/Linux
31+
curl -LsSf https://astral.sh/uv/install.sh | sh
32+
33+
# Or with Homebrew
34+
brew install uv
35+
```
36+
37+
Then install the development dependencies:
38+
39+
```bash
40+
uv sync
41+
```
42+
2543
## Generating Documentation
2644

2745
This module uses [terraform-docs](https://terraform-docs.io/user-guide/introduction/) to generate documentation. To generate the documentation, run the following command from the root of the repository:
@@ -30,6 +48,26 @@ This module uses [terraform-docs](https://terraform-docs.io/user-guide/introduct
3048
.github/scripts/generate-docs.sh
3149
```
3250

51+
## Generating Terraform Type Definitions
52+
53+
The Terraform variable type definitions are auto-generated from the upstream Materialize CRD and Helm chart schemas. The version is read from the `environmentd_version` variable default in the source code.
54+
55+
To regenerate:
56+
57+
```bash
58+
uv run python scripts/generate_terraform_types.py
59+
```
60+
61+
### Checking Schema Sync
62+
63+
To verify that the generated Terraform types are in sync with upstream schemas:
64+
65+
```bash
66+
uv run python scripts/check_schema_sync.py
67+
```
68+
69+
This check runs automatically in CI via the `check-schema-sync` workflow.
70+
3371
## Development Process
3472

3573
1. Clone the repository

scripts/check_schema_sync.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Check that generated Terraform type definitions are in sync with upstream schemas.
4+
5+
Runs the generation script and checks if any files changed.
6+
7+
Exit codes:
8+
0: All files in sync
9+
1: Files out of sync or uncommitted changes exist
10+
"""
11+
12+
import subprocess
13+
import sys
14+
from pathlib import Path
15+
16+
SCRIPT_DIR = Path(__file__).parent
17+
REPO_ROOT = SCRIPT_DIR.parent
18+
19+
GENERATED_FILES = [
20+
"kubernetes/modules/materialize-instance/crd_variables.gen.tf",
21+
"aws/modules/operator/helm_variables.gen.tf",
22+
"azure/modules/operator/helm_variables.gen.tf",
23+
"gcp/modules/operator/helm_variables.gen.tf",
24+
"aws/examples/simple/override_variables.gen.tf",
25+
"azure/examples/simple/override_variables.gen.tf",
26+
"gcp/examples/simple/override_variables.gen.tf",
27+
]
28+
29+
30+
def main():
31+
# Check for uncommitted changes to generated files
32+
result = subprocess.run(
33+
["git", "diff", "--name-only", "--"] + GENERATED_FILES,
34+
capture_output=True,
35+
text=True,
36+
cwd=REPO_ROOT,
37+
)
38+
if result.stdout.strip():
39+
print("Error: Uncommitted changes to generated files:", file=sys.stderr)
40+
print(result.stdout, file=sys.stderr)
41+
sys.exit(1)
42+
43+
# Run generation
44+
print("Running generate_terraform_types.py...")
45+
result = subprocess.run(
46+
[sys.executable, str(SCRIPT_DIR / "generate_terraform_types.py")],
47+
cwd=REPO_ROOT,
48+
)
49+
if result.returncode != 0:
50+
sys.exit(result.returncode)
51+
52+
# Check for diff
53+
result = subprocess.run(
54+
["git", "diff", "--name-only", "--"] + GENERATED_FILES,
55+
capture_output=True,
56+
text=True,
57+
cwd=REPO_ROOT,
58+
)
59+
if result.stdout.strip():
60+
print("\nError: Generated files are out of sync:", file=sys.stderr)
61+
print(result.stdout, file=sys.stderr)
62+
print(
63+
"\nRun 'uv run python scripts/generate_terraform_types.py' to update.",
64+
file=sys.stderr,
65+
)
66+
sys.exit(1)
67+
68+
print("\nAll generated files are in sync.")
69+
70+
71+
if __name__ == "__main__":
72+
main()

0 commit comments

Comments
 (0)