-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
airbyte-ci: CLI exposes CI requirements #34218
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,14 @@ | |
import functools | ||
import inspect | ||
from functools import wraps | ||
from typing import Any, Callable, Type | ||
from typing import Any, Callable, Type, TypeVar | ||
|
||
import asyncclick as click | ||
from pipelines.models.ci_requirements import CIRequirements | ||
|
||
_AnyCallable = Callable[..., Any] | ||
FC = TypeVar("FC", bound="_AnyCallable | click.core.Command") | ||
CI_REQUIREMENTS_OPTION_NAME = "--ci-requirements" | ||
|
||
|
||
def _contains_var_kwarg(f: Callable) -> bool: | ||
|
@@ -121,3 +126,27 @@ def decorated_function(*args: Any, **kwargs: Any) -> Any: # noqa: ANN401 | |
return f(*args, **kwargs) | ||
|
||
return decorated_function | ||
|
||
|
||
def click_ci_requirements_option() -> Callable[[FC], FC]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can eventually add arguments to this decorator to customize requirements according to commands. |
||
"""Add a --ci-requirements option to the command. | ||
|
||
Returns: | ||
Callable[[FC], FC]: The decorated command. | ||
""" | ||
|
||
def callback(ctx: click.Context, param: click.Parameter, value: bool) -> None: | ||
if value: | ||
ci_requirements = CIRequirements() | ||
click.echo(ci_requirements.to_json()) | ||
ctx.exit() | ||
|
||
return click.decorators.option( | ||
CI_REQUIREMENTS_OPTION_NAME, | ||
is_flag=True, | ||
expose_value=False, | ||
is_eager=True, | ||
flag_value=True, | ||
help="Show the CI requirements and exit. It used to make airbyte-ci client define the CI runners it will run on.", | ||
callback=callback, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
|
||
import json | ||
from dataclasses import dataclass | ||
from importlib import metadata | ||
|
||
INFRA_SUPPORTED_DAGGER_VERSIONS = { | ||
"0.6.4", | ||
"0.9.5", | ||
} | ||
|
||
|
||
@dataclass | ||
class CIRequirements: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used a dataclass here in case we want to make the CI requirements payload a bit more complex. It does not have custom attributes at the moment but we can easily add some if needed. |
||
""" | ||
A dataclass to store the CI requirements. | ||
It used to make airbyte-ci client define the CI runners it will run on. | ||
""" | ||
|
||
dagger_version = metadata.version("dagger-io") | ||
|
||
def __post_init__(self) -> None: | ||
if self.dagger_version not in INFRA_SUPPORTED_DAGGER_VERSIONS: | ||
raise ValueError( | ||
f"Unsupported dagger version: {self.dagger_version}. " f"Supported versions are: {INFRA_SUPPORTED_DAGGER_VERSIONS}." | ||
) | ||
|
||
def to_json(self) -> str: | ||
return json.dumps( | ||
{ | ||
"dagger_version": self.dagger_version, | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💅 Note for future: We do need to invert this at some point where commands specifiy if they need dagger run or not.