-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add invoke command to generate repository schema for the SDK
- Loading branch information
Showing
4 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,6 @@ python_sdk/dist/* | |
|
||
# Test reports | ||
**/*.csv | ||
|
||
# Generated files | ||
generated/ |
1 change: 1 addition & 0 deletions
1
backend/tests/fixtures/repos/car-dealership/initial__main/.infrahub.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pathlib import Path | ||
|
||
from invoke.context import Context | ||
from invoke.tasks import task | ||
|
||
from .utils import REPO_BASE | ||
|
||
SDK_DIRECTORY = f"{REPO_BASE}/generated/python-sdk" | ||
INFRAHUB_DIRECTORY = f"{REPO_BASE}/generated/python-sdk" | ||
|
||
|
||
@task | ||
def generate_jsonschema(context: Context): | ||
"""Generate JSON schemas into ./generated""" | ||
|
||
generate_sdk_repository_config() | ||
|
||
|
||
def generate_sdk_repository_config(): | ||
from infrahub_sdk.schema import InfrahubRepositoryConfig | ||
|
||
repository_dir = f"{SDK_DIRECTORY}/repository-config" | ||
Path(repository_dir).mkdir(parents=True, exist_ok=True) | ||
schema = InfrahubRepositoryConfig.schema_json(indent=4) | ||
|
||
write(filename=f"{repository_dir}/develop.json", content=schema) | ||
|
||
|
||
def write(filename: str, content: str) -> None: | ||
with open(filename, "w", encoding="utf-8") as fobj: | ||
fobj.write(content) | ||
print(f"Wrote to {filename}") |