Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
86 changes: 82 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
if: |
always() && !cancelled() &&
!contains(needs.*.result, 'failure') &&
Expand All @@ -144,7 +143,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: "Setup environment"
run: |
pipx install poetry==1.8.5
pipx install poetry==1.8.5 --python python${{ matrix.python-version }}
poetry config virtualenvs.create true --local
pip install invoke toml codecov
- name: "Install Package"
Expand Down Expand Up @@ -174,7 +173,7 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# ------------------------------------------ Integration Tests ------------------------------------------
integration-tests:
integration-tests-latest-infrahub:
if: |
always() && !cancelled() &&
!contains(needs.*.result, 'failure') &&
Expand Down Expand Up @@ -202,8 +201,87 @@ jobs:
pip install invoke toml codecov
- name: "Install Package"
run: "poetry install --all-extras"
- name: "Set environment variables for python_testcontainers"
run: |
echo INFRAHUB_TESTING_IMAGE_VER=latest >> $GITHUB_ENV
- name: "Integration Tests"
run: |
poetry run pytest --cov infrahub_sdk tests/integration/
- name: "Upload coverage to Codecov"
run: |
codecov --flags integration-tests
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

integration-tests-local-infrahub:
if: |
always() && !cancelled() &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled') &&
needs.files-changed.outputs.python == 'true' &&
(github.base_ref == 'stable' || github.base_ref == 'develop')
needs: ["files-changed", "yaml-lint", "python-lint"]
runs-on:
group: "huge-runners"
timeout-minutes: 30
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"

- name: "Extract target branch name"
id: extract_branch
run: echo "TARGET_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV

- name: "Checkout infrahub repository"
uses: "actions/checkout@v4"
with:
repository: "opsmill/infrahub"
path: "infrahub-server"
ref: ${{ github.base_ref }}
submodules: true

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: "Setup git credentials prior dev.build"
run: |
cd infrahub-server
git config --global user.name 'Infrahub'
git config --global user.email 'infrahub@opsmill.com'
git config --global --add safe.directory '*'
git config --global credential.usehttppath true
git config --global credential.helper /usr/local/bin/infrahub-git-credential

- name: "Set environment variables prior dev.build"
run: |
echo "INFRAHUB_BUILD_NAME=infrahub-${{ runner.name }}" >> $GITHUB_ENV
RUNNER_NAME=$(echo "${{ runner.name }}" | grep -o 'ghrunner[0-9]\+' | sed 's/ghrunner\([0-9]\+\)/ghrunner_\1/')
echo "PYTEST_DEBUG_TEMPROOT=/var/lib/github/${RUNNER_NAME}/_temp" >> $GITHUB_ENV
echo "INFRAHUB_IMAGE_VER=local-${{ runner.name }}-${{ github.sha }}" >> $GITHUB_ENV
echo "INFRAHUB_TESTING_IMAGE_VER=local-${{ runner.name }}-${{ github.sha }}" >> $GITHUB_ENV
echo "INFRAHUB_TESTING_DOCKER_IMAGE=opsmill/infrahub" >> $GITHUB_ENV

- name: "Build container"
run: |
cd infrahub-server
inv dev.build

- name: "Setup environment"
run: |
pipx install poetry==1.8.5
poetry config virtualenvs.create true --local
pip install invoke toml codecov

- name: "Install Package"
run: "poetry install --all-extras"

- name: "Integration Tests"
run: "poetry run pytest --cov infrahub_sdk tests/integration/"
run: |
echo "Running tests for version: $INFRAHUB_TESTING_IMAGE_VER"
poetry run pytest --cov infrahub_sdk tests/integration/

- name: "Upload coverage to Codecov"
run: |
codecov --flags integration-tests
Expand Down
1 change: 1 addition & 0 deletions changelog/+add-logger-to-generator-class.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added logger to `InfrahubGenerator` class to allow users use built-in logging (`self.logger`) to show logging within Infrahub CI pipeline.
1 change: 1 addition & 0 deletions changelog/+artifact_methods.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changes InfrahubNode `artifact_fetch` and `artifact_generate` methods to use the name of the artifact instead of the name of the artifact definition
1 change: 1 addition & 0 deletions changelog/+move-read-file.housekeeping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move the function `read_file` from the ctl module to the SDK.
1 change: 1 addition & 0 deletions changelog/104.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `protocols` CTL command properly gets default branch setting from environment variable
1 change: 1 addition & 0 deletions changelog/251.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix typing for Python 3.9 and remove support for Python 3.13
1 change: 1 addition & 0 deletions changelog/264.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove default value "main" for branch parameter from all Infrahub CTL commands.
13 changes: 0 additions & 13 deletions infrahub_sdk/ctl/_file.py

This file was deleted.

6 changes: 3 additions & 3 deletions infrahub_sdk/ctl/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from asyncio import run as aiorun
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

import typer
from rich.console import Console
Expand Down Expand Up @@ -50,8 +50,8 @@ def run(
format_json: bool,
list_available: bool,
variables: dict[str, str],
name: str | None = None,
branch: str | None = None,
name: Optional[str] = None,
branch: Optional[str] = None,
) -> None:
"""Locate and execute all checks under the defined path."""

Expand Down
21 changes: 11 additions & 10 deletions infrahub_sdk/ctl/cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import platform
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable
from typing import TYPE_CHECKING, Any, Callable, Optional

import jinja2
import typer
Expand Down Expand Up @@ -74,13 +74,13 @@
@catch_exception(console=console)
def check(
check_name: str = typer.Argument(default="", help="Name of the Python check"),
branch: str | None = None,
branch: Optional[str] = None,
path: str = typer.Option(".", help="Root directory"),
debug: bool = False,
format_json: bool = False,
_: str = CONFIG_PARAM,
list_available: bool = typer.Option(False, "--list", help="Show available Python checks"),
variables: list[str] | None = typer.Argument(
variables: Optional[list[str]] = typer.Argument(
None, help="Variables to pass along with the query. Format key=value key=value."
),
) -> None:
Expand All @@ -102,12 +102,12 @@ def check(
@catch_exception(console=console)
async def generator(
generator_name: str = typer.Argument(default="", help="Name of the Generator"),
branch: str | None = None,
branch: Optional[str] = None,
path: str = typer.Option(".", help="Root directory"),
debug: bool = False,
_: str = CONFIG_PARAM,
list_available: bool = typer.Option(False, "--list", help="Show available Generators"),
variables: list[str] | None = typer.Argument(
variables: Optional[list[str]] = typer.Argument(
None, help="Variables to pass along with the query. Format key=value key=value."
),
) -> None:
Expand All @@ -129,14 +129,14 @@ async def run(
method: str = "run",
debug: bool = False,
_: str = CONFIG_PARAM,
branch: str = typer.Option("main", help="Branch on which to run the script."),
concurrent: int | None = typer.Option(
branch: str = typer.Option(None, help="Branch on which to run the script."),
concurrent: Optional[int] = typer.Option(
None,
help="Maximum number of requests to execute at the same time.",
envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",
),
timeout: int = typer.Option(60, help="Timeout in sec", envvar="INFRAHUB_TIMEOUT"),
variables: list[str] | None = typer.Argument(
variables: Optional[list[str]] = typer.Argument(
None, help="Variables to pass along with the query. Format key=value key=value."
),
) -> None:
Expand Down Expand Up @@ -259,7 +259,7 @@ def _run_transform(
@catch_exception(console=console)
def render(
transform_name: str = typer.Argument(default="", help="Name of the Python transformation", show_default=False),
variables: list[str] | None = typer.Argument(
variables: Optional[list[str]] = typer.Argument(
None, help="Variables to pass along with the query. Format key=value key=value."
),
branch: str = typer.Option(None, help="Branch on which to render the transform."),
Expand Down Expand Up @@ -309,7 +309,7 @@ def render(
@catch_exception(console=console)
def transform(
transform_name: str = typer.Argument(default="", help="Name of the Python transformation", show_default=False),
variables: list[str] | None = typer.Argument(
variables: Optional[list[str]] = typer.Argument(
None, help="Variables to pass along with the query. Format key=value key=value."
),
branch: str = typer.Option(None, help="Branch on which to run the transformation"),
Expand Down Expand Up @@ -383,6 +383,7 @@ def protocols(

else:
client = initialize_client_sync()
branch = branch or client.default_branch
schema.update(client.schema.fetch(branch=branch))

code_generator = CodeGenerator(schema=schema)
Expand Down
6 changes: 0 additions & 6 deletions infrahub_sdk/ctl/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@ class QueryNotFoundError(Error):
def __init__(self, name: str, message: str = ""):
self.message = message or f"The requested query '{name}' was not found."
super().__init__(self.message)


class FileNotValidError(Error):
def __init__(self, name: str, message: str = ""):
self.message = message or f"Cannot parse '{name}' content."
super().__init__(self.message)
2 changes: 1 addition & 1 deletion infrahub_sdk/ctl/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def dump(
directory: Path = typer.Option(directory_name_with_timestamp, help="Directory path to store export"),
quiet: bool = typer.Option(False, help="No console output"),
_: str = CONFIG_PARAM,
branch: str = typer.Option("main", help="Branch from which to export"),
branch: str = typer.Option(None, help="Branch from which to export"),
concurrent: int = typer.Option(
4,
help="Maximum number of requests to execute at the same time.",
Expand Down
10 changes: 5 additions & 5 deletions infrahub_sdk/ctl/generator.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

import typer
from rich.console import Console

from ..ctl import config
from ..ctl.client import initialize_client
from ..ctl.repository import get_repository_config
from ..ctl.utils import execute_graphql_query, parse_cli_vars
from ..ctl.utils import execute_graphql_query, init_logging, parse_cli_vars
from ..exceptions import ModuleImportError
from ..node import InfrahubNode

Expand All @@ -20,11 +20,12 @@
async def run(
generator_name: str,
path: str, # noqa: ARG001
debug: bool, # noqa: ARG001
debug: bool,
list_available: bool,
branch: str | None = None,
variables: list[str] | None = None,
variables: Optional[list[str]] = None,
) -> None:
init_logging(debug=debug)
repository_config = get_repository_config(Path(config.INFRAHUB_REPO_CONFIG_FILE))

if list_available or not generator_name:
Expand All @@ -34,7 +35,6 @@ async def run(
generator_config = repository_config.get_generator_definition(name=generator_name)

console = Console()

relative_path = str(generator_config.file_path.parent) if generator_config.file_path.parent != Path() else None

try:
Expand Down
5 changes: 3 additions & 2 deletions infrahub_sdk/ctl/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from asyncio import run as aiorun
from pathlib import Path
from typing import Optional

import typer
from rich.console import Console
Expand All @@ -25,8 +26,8 @@ def load(
),
quiet: bool = typer.Option(False, help="No console output"),
_: str = CONFIG_PARAM,
branch: str = typer.Option("main", help="Branch from which to export"),
concurrent: int | None = typer.Option(
branch: str = typer.Option(None, help="Branch from which to export"),
concurrent: Optional[int] = typer.Option(
None,
help="Maximum number of requests to execute at the same time.",
envvar="INFRAHUB_MAX_CONCURRENT_EXECUTION",
Expand Down
2 changes: 1 addition & 1 deletion infrahub_sdk/ctl/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def callback() -> None:
async def load(
menus: list[Path],
debug: bool = False,
branch: str = typer.Option("main", help="Branch on which to load the menu."),
branch: str = typer.Option(None, help="Branch on which to load the menu."),
_: str = CONFIG_PARAM,
) -> None:
"""Load one or multiple menu files into Infrahub."""
Expand Down
2 changes: 1 addition & 1 deletion infrahub_sdk/ctl/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def callback() -> None:
async def load(
paths: list[Path],
debug: bool = False,
branch: str = typer.Option("main", help="Branch on which to load the objects."),
branch: str = typer.Option(None, help="Branch on which to load the objects."),
_: str = CONFIG_PARAM,
) -> None:
"""Load one or multiple objects files into Infrahub."""
Expand Down
Loading
Loading