Skip to content

Commit b564db6

Browse files
authored
Cover schema extensions ci (#26)
* Format * Add a task to load extensions * Add step in ci pipeline * Support 3 degrees of dependencies * Add doc * Improve CI file * Add quick example for loading schema
1 parent f1f808a commit b564db6

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
filters: .github/file-filters.yml
3333

3434
yaml-lint:
35+
name: Run yaml lint
3536
if: needs.files-changed.outputs.yaml == 'true'
3637
needs: ["files-changed"]
3738
runs-on: "ubuntu-latest"
@@ -44,7 +45,9 @@ jobs:
4445
- name: "Linting: yamllint"
4546
run: "yamllint -s ."
4647

47-
E2E-testing-invoke-start:
48+
# FIXME: This should be triggered only when some YAML schema changes...
49+
schema-test:
50+
name: Test all schema files
4851
needs:
4952
- files-changed
5053
- yaml-lint
@@ -91,9 +94,8 @@ jobs:
9194
- name: Test base schema files
9295
run: invoke load-schema-base
9396

94-
# NOTE: Doesn't work now
95-
# - name: Test experimental schema files
96-
# run: invoke load-schema-experimental
97+
- name: Test extensions schema files
98+
run: invoke load-schema-extensions
9799

98100
- name: "Clear docker environment and force vmagent to stop"
99101
if: always()

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ Welcome to the Schema Library for Infrahub! This repository offers a collection
1313
There are several ways to [load a schema in Infrahub](https://docs.infrahub.app/guides/import-schema):
1414

1515
- Quick View: To take a quick look at a schema, you can use Infrahub CTL. Follow [this guide](https://docs.infrahub.app/infrahubctl) to install Infrahub CTL.
16+
17+
```console
18+
# Load the base
19+
infrahubctl schema load base
20+
21+
# Load an extension
22+
infrahubctl schema load extensions/location_minimal
23+
```
24+
1625
- Controlled Integration: For a more organized and unified approach to loading schemas, you can connect a Git repository. Follow [this guide](https://docs.infrahub.app/guides/repository) to connect a Git repository.
1726

1827
> [!NOTE]

tasks.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,70 @@
11
import os
2-
32
from pathlib import Path
43

5-
from invoke import task, Context # type: ignore
4+
from invoke import Context, task # type: ignore
65

76
# If no version is indicated, we will take the latest
87
VERSION = os.getenv("INFRAHUB_VERSION", None)
98
DOCKER_PROJECT = os.getenv("INFRAHUB_BUILD_NAME", "schema-library-ci")
109
COMPOSE_COMMAND = f"curl https://infrahub.opsmill.io/{VERSION if VERSION else ''} | sed 's/8000:8000/0:8000/' | docker compose -p {DOCKER_PROJECT} -f -"
1110

11+
12+
def _parse_and_load_extensions(
13+
context: Context, extensions_path: Path, allowed_to_fail: bool
14+
) -> None:
15+
# Looping over all entries in extensions dir
16+
for entry in os.listdir(extensions_path):
17+
# Make sure it's a dir
18+
# TODO: here if in extensions folder we have a dir without schema it will fail
19+
if os.path.isdir(extensions_path / entry):
20+
print(f"Loading `{entry}`")
21+
22+
# Load extensions
23+
# TODO: Maybe improve what we return here...
24+
context.run(
25+
f"infrahubctl schema load {extensions_path / entry}",
26+
warn=allowed_to_fail,
27+
)
28+
29+
1230
@task
1331
def start(context: Context) -> None:
1432
context.run(f"{COMPOSE_COMMAND} up -d --wait")
1533

34+
1635
@task
17-
def load_schema_base(context: Context, schema: Path=Path("./base/*.yml")) -> None:
18-
context.run(f"infrahubctl schema load {schema}")
36+
def load_schema_base(context: Context) -> None:
37+
base_path = Path("./base")
38+
context.run(f"infrahubctl schema load {base_path}")
39+
1940

2041
@task
21-
def load_schema_experimental(context: Context, schema: Path=Path("./experimental/**/*.yml")) -> None:
22-
Base=Path("./base/*.yml")
23-
context.run(f"infrahubctl schema load {Base}")
24-
context.run(f"infrahubctl schema load {schema}")
42+
def load_schema_extensions(context: Context) -> None:
43+
extensions_path = Path("./extensions")
44+
45+
# FIXME: Find a more efficient way to deal with dependencies that doesn't
46+
# require developer to explicitly maintain it
47+
48+
# First/second loop: here we allow to fail so it will load as much as it can
49+
print("Loading all extensions once ...")
50+
_parse_and_load_extensions(context, extensions_path, True)
51+
52+
print("Loading all extensions second time ...")
53+
_parse_and_load_extensions(context, extensions_path, True)
54+
55+
# Third loop: all the dependencies are loaded it MUST work
56+
print("Loading all extensions third time ...")
57+
_parse_and_load_extensions(context, extensions_path, True)
58+
59+
# FIXME: If we have 4 degrees of dependencies it won't work
60+
print("All good!")
61+
2562

2663
@task
2764
def destroy(context: Context) -> None:
2865
context.run(f"{COMPOSE_COMMAND} down -v")
2966

67+
3068
@task
3169
def stop(context: Context) -> None:
3270
context.run(f"{COMPOSE_COMMAND} down")
33-
34-
@task
35-
def restart(context: Context, component: str="")-> None:
36-
if component:
37-
context.run(f"{COMPOSE_COMMAND} restart {component}")
38-
return
39-
40-
context.run(f"{COMPOSE_COMMAND} restart")

0 commit comments

Comments
 (0)