Skip to content
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: Add ClickPipelineContext and update test to use #31628

Merged
merged 36 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a4994f4
Add lazy decorator
bnchrch Oct 19, 2023
ccddd26
Add playground subcommands
bnchrch Oct 19, 2023
96643f1
steal
bnchrch Oct 19, 2023
efa0786
Show demo of context coming through
bnchrch Oct 19, 2023
76458dc
Add pass_click_context_and_args_to_children
bnchrch Oct 19, 2023
58845d3
Add click decorator to reduce boilerplate
bnchrch Oct 19, 2023
435f44d
Add click_append_to_context_object decorator
bnchrch Oct 19, 2023
55baf8f
Move files
bnchrch Oct 19, 2023
8bfe2aa
Automated Commit - Formatting Changes
bnchrch Oct 19, 2023
a9b7365
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Oct 24, 2023
27043ae
Bring up to date with async click
bnchrch Oct 24, 2023
c53310a
Replace test with playground impl
bnchrch Oct 24, 2023
b07da00
Add singleton test
bnchrch Oct 24, 2023
03a14c9
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Oct 30, 2023
714d201
Fix low hanging comments
bnchrch Oct 31, 2023
29087ea
Automated Commit - Formatting Changes
bnchrch Oct 31, 2023
fb43cfb
Move decorator to file
bnchrch Oct 31, 2023
323139d
Add tests
bnchrch Nov 1, 2023
f624fa3
Add forgotten test
bnchrch Nov 1, 2023
24297df
Update ctx to click pipeline context
bnchrch Nov 1, 2023
58b28af
Add cli tests
bnchrch Nov 2, 2023
a4e1efb
Remove async
bnchrch Nov 2, 2023
b1e479b
Add async back
bnchrch Nov 2, 2023
d89f7f3
Add doc string
bnchrch Nov 2, 2023
6855ba3
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Nov 2, 2023
7ca02fc
Automated Commit - Formatting Changes
bnchrch Nov 2, 2023
bcee91f
Run license check on repo (#32154)
erohmensing Nov 6, 2023
77858b7
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Nov 7, 2023
fd5e49c
Use ctx params instead of args
bnchrch Nov 7, 2023
38521a1
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Nov 7, 2023
c290dd8
Revert additional formating
bnchrch Nov 7, 2023
3dc9853
Automated Commit - Formatting Changes
bnchrch Nov 7, 2023
1aeb577
Fix tests
bnchrch Nov 7, 2023
cf50807
Remove comment
bnchrch Nov 7, 2023
755d02a
Merge remote-tracking branch 'origin/master' into bnchrch/simple-pipe…
bnchrch Nov 7, 2023
7ff56fb
Remove unused command
bnchrch Nov 7, 2023
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
7 changes: 4 additions & 3 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ If you face any installation problems feel free to reach out the Airbyte Connect
### Setting up connector secrets access

If you plan to use Airbyte CI to run CAT (Connector Acceptance Tests), we recommend setting up GSM
access so that Airbyte CI can pull remote secrets from GSM. For setup instructions, see the
CI Credentials package (which Airbyte CI uses under the hood) README's
access so that Airbyte CI can pull remote secrets from GSM. For setup instructions, see the
CI Credentials package (which Airbyte CI uses under the hood) README's
[Get GSM Access](https://github.com/airbytehq/airbyte/blob/master/airbyte-ci/connectors/ci_credentials/README.md#get-gsm-access)
instructions.

Expand Down Expand Up @@ -155,7 +155,7 @@ Available commands:
| `--enable-dependency-scanning / --disable-dependency-scanning` | False | ` --disable-dependency-scanning` | | When enabled the dependency scanning will be performed to detect the connectors to select according to a dependency change. |
| `--docker-hub-username` | | | DOCKER_HUB_USERNAME | Your username to connect to DockerHub. Required for the publish subcommand. |
| `--docker-hub-password` | | | DOCKER_HUB_PASSWORD | Your password to connect to DockerHub. Required for the publish subcommand. |


### <a id="connectors-list-command"></a>`connectors list` command
Retrieve the list of connectors satisfying the provided filters.
Expand Down Expand Up @@ -408,6 +408,7 @@ This command runs the Python tests for a airbyte-ci poetry package.
## Changelog
| Version | PR | Description |
| ------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| 2.5.7 | [#31628](https://github.com/airbytehq/airbyte/pull/31628) | Add ClickPipelineContext class |
| 2.5.6 | [#32139](https://github.com/airbytehq/airbyte/pull/32139) | Test coverage report on Python connector UnitTest. |
| 2.5.5 | [#32114](https://github.com/airbytehq/airbyte/pull/32114) | Create cache mount for `/var/lib/docker` to store images in `dind` context. |
| 2.5.4 | [#32090](https://github.com/airbytehq/airbyte/pull/32090) | Do not cache `docker login`. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def build(ctx: click.Context, use_host_gradle_dist_tar: bool) -> bool:
ci_context=ctx.obj.get("ci_context"),
ci_gcs_credentials=ctx.obj["ci_gcs_credentials"],
use_local_cdk=ctx.obj.get("use_local_cdk"),
open_report_in_browser=ctx.obj.get("open_report_in_browser"),
enable_report_auto_open=ctx.obj.get("enable_report_auto_open"),
use_host_gradle_dist_tar=use_host_gradle_dist_tar,
s3_build_cache_access_key_id=ctx.obj.get("s3_build_cache_access_key_id"),
s3_build_cache_secret_key=ctx.obj.get("s3_build_cache_secret_key"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def bump_version(
ci_gcs_credentials=ctx.obj["ci_gcs_credentials"],
ci_git_user=ctx.obj["ci_git_user"],
ci_github_access_token=ctx.obj["ci_github_access_token"],
open_report_in_browser=False,
enable_report_auto_open=False,
s3_build_cache_access_key_id=ctx.obj.get("s3_build_cache_access_key_id"),
s3_build_cache_secret_key=ctx.obj.get("s3_build_cache_secret_key"),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import asyncclick as click
from connector_ops.utils import ConnectorLanguage, SupportLevelEnum, get_all_connectors_in_repo
from pipelines import main_logger
from pipelines.cli.click_decorators import click_append_to_context_object, click_ignore_unused_kwargs, click_merge_args_into_context_obj
from pipelines.cli.lazy_group import LazyGroup
from pipelines.helpers.connectors.modifed import ConnectorWithModifiedFiles, get_connector_modified_files, get_modified_connectors

Expand Down Expand Up @@ -225,43 +226,24 @@ def should_use_remote_secrets(use_remote_secrets: Optional[bool]) -> bool:
required=False,
envvar="DOCKER_HUB_PASSWORD",
)
@click_merge_args_into_context_obj
@click_append_to_context_object("use_remote_secrets", lambda ctx: should_use_remote_secrets(ctx.obj["use_remote_secrets"]))
@click.pass_context
@click_ignore_unused_kwargs
async def connectors(
ctx: click.Context,
use_remote_secrets: Optional[bool],
names: Tuple[str],
languages: Tuple[ConnectorLanguage],
support_levels: Tuple[str],
modified: bool,
metadata_changes_only: bool,
metadata_query: str,
concurrency: int,
execute_timeout: int,
enable_dependency_scanning: bool,
use_local_cdk: bool,
enable_report_auto_open: bool,
docker_hub_username: str,
docker_hub_password: str,
):
"""Group all the connectors-ci command."""
validate_environment(ctx.obj["is_local"])

ctx.ensure_object(dict)
ctx.obj["use_remote_secrets"] = should_use_remote_secrets(use_remote_secrets)
ctx.obj["concurrency"] = concurrency
ctx.obj["execute_timeout"] = execute_timeout
ctx.obj["use_local_cdk"] = use_local_cdk
ctx.obj["open_report_in_browser"] = enable_report_auto_open
ctx.obj["docker_hub_username"] = docker_hub_username
ctx.obj["docker_hub_password"] = docker_hub_password
ctx.obj["selected_connectors_with_modified_files"] = get_selected_connectors_with_modified_files(
names,
support_levels,
languages,
modified,
metadata_changes_only,
metadata_query,
ctx.obj["names"],
ctx.obj["support_levels"],
ctx.obj["languages"],
ctx.obj["modified"],
ctx.obj["metadata_changes_only"],
ctx.obj["metadata_query"],
ctx.obj["modified_files"],
enable_dependency_scanning,
ctx.obj["enable_dependency_scanning"],
)
log_selected_connectors(ctx.obj["selected_connectors_with_modified_files"])
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pipelines.helpers.github import update_commit_status_check
from pipelines.helpers.slack import send_message_to_webhook
from pipelines.helpers.utils import METADATA_FILE_NAME
from pipelines.models.contexts import PipelineContext
from pipelines.models.contexts.pipeline_context import PipelineContext


class ConnectorContext(PipelineContext):
Expand Down Expand Up @@ -54,7 +54,7 @@ def __init__(
code_tests_only: bool = False,
use_local_cdk: bool = False,
use_host_gradle_dist_tar: bool = False,
open_report_in_browser: bool = True,
enable_report_auto_open: bool = True,
docker_hub_username: Optional[str] = None,
docker_hub_password: Optional[str] = None,
s3_build_cache_access_key_id: Optional[str] = None,
Expand Down Expand Up @@ -82,7 +82,7 @@ def __init__(
fast_tests_only (bool, optional): Whether to run only fast tests. Defaults to False.
code_tests_only (bool, optional): Whether to ignore non-code tests like QA and metadata checks. Defaults to False.
use_host_gradle_dist_tar (bool, optional): Used when developing java connectors with gradle. Defaults to False.
open_report_in_browser (bool, optional): Open HTML report in browser window. Defaults to True.
enable_report_auto_open (bool, optional): Open HTML report in browser window. Defaults to True.
docker_hub_username (Optional[str], optional): Docker Hub username to use to read registries. Defaults to None.
docker_hub_password (Optional[str], optional): Docker Hub password to use to read registries. Defaults to None.
s3_build_cache_access_key_id (Optional[str], optional): Gradle S3 Build Cache credentials. Defaults to None.
Expand All @@ -104,7 +104,7 @@ def __init__(
self.code_tests_only = code_tests_only
self.use_local_cdk = use_local_cdk
self.use_host_gradle_dist_tar = use_host_gradle_dist_tar
self.open_report_in_browser = open_report_in_browser
self.enable_report_auto_open = enable_report_auto_open
self.docker_hub_username = docker_hub_username
self.docker_hub_password = docker_hub_password
self.s3_build_cache_access_key_id = s3_build_cache_access_key_id
Expand All @@ -127,7 +127,7 @@ def __init__(
ci_gcs_credentials=ci_gcs_credentials,
ci_git_user=ci_git_user,
ci_github_access_token=ci_github_access_token,
open_report_in_browser=open_report_in_browser,
enable_report_auto_open=enable_report_auto_open,
)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def migrate_to_base_image(
ci_gcs_credentials=ctx.obj["ci_gcs_credentials"],
ci_git_user=ctx.obj["ci_git_user"],
ci_github_access_token=ctx.obj["ci_github_access_token"],
open_report_in_browser=False,
enable_report_auto_open=False,
docker_hub_username=ctx.obj.get("docker_hub_username"),
docker_hub_password=ctx.obj.get("docker_hub_password"),
s3_build_cache_access_key_id=ctx.obj.get("s3_build_cache_access_key_id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ async def to_html(self) -> str:
async def save(self) -> None:
local_html_path = await self.save_local(self.html_report_file_name, await self.to_html())
absolute_path = await local_html_path.resolve()
if self.pipeline_context.open_report_in_browser:
if self.pipeline_context.enable_report_auto_open:
self.pipeline_context.logger.info(f"HTML report saved locally: {absolute_path}")
if self.pipeline_context.open_report_in_browser:
if self.pipeline_context.enable_report_auto_open:
self.pipeline_context.logger.info("Opening HTML report in browser.")
webbrowser.open(absolute_path.as_uri())
if self.remote_storage_enabled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pipelines.dagger.actions import secrets
from pipelines.dagger.containers import internal_tools
from pipelines.helpers.utils import METADATA_FILE_NAME
from pipelines.models.contexts import PipelineContext
from pipelines.models.contexts.pipeline_context import PipelineContext
from pipelines.models.steps import Step, StepResult, StepStatus


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def upgrade_base_image(ctx: click.Context, set_if_not_exists: bool, docker
ci_gcs_credentials=ctx.obj["ci_gcs_credentials"],
ci_git_user=ctx.obj["ci_git_user"],
ci_github_access_token=ctx.obj["ci_github_access_token"],
open_report_in_browser=False,
enable_report_auto_open=False,
docker_hub_username=ctx.obj.get("docker_hub_username"),
docker_hub_password=ctx.obj.get("docker_hub_password"),
s3_build_cache_access_key_id=ctx.obj.get("s3_build_cache_access_key_id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import dagger
from pipelines.dagger.actions.python.pipx import with_installed_pipx_package
from pipelines.dagger.containers.python import with_python_base
from pipelines.models.contexts import PipelineContext
from pipelines.models.contexts.pipeline_context import PipelineContext
from pipelines.models.steps import MountPath, Step, StepResult


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pipelines.consts import AMAZONCORRETTO_IMAGE
from pipelines.dagger.actions import secrets
from pipelines.helpers.utils import sh_dash_c
from pipelines.models.contexts import PipelineContext
from pipelines.models.contexts.pipeline_context import PipelineContext
from pipelines.models.steps import Step, StepResult


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

from pipelines.models.contexts import PipelineContext
from pipelines.models.contexts.pipeline_context import PipelineContext
from pipelines.models.steps import Step, StepResult, StepStatus


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

from pipelines.dagger.actions.python.poetry import with_poetry_module
from pipelines.models.contexts import PipelineContext
from pipelines.models.contexts.pipeline_context import PipelineContext
from pipelines.models.steps import Step, StepResult


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,68 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

import logging

import asyncclick as click
from pipelines.airbyte_ci.test.pipeline import run_test
from pipelines.cli.click_decorators import click_ignore_unused_kwargs, click_merge_args_into_context_obj
from pipelines.consts import DOCKER_VERSION
from pipelines.helpers.utils import sh_dash_c
from pipelines.models.contexts.click_pipeline_context import ClickPipelineContext, pass_pipeline_context


@click.command()
@click.argument("poetry_package_path")
@click.option("--test-directory", default="tests", help="The directory containing the tests to run.")
async def test(
poetry_package_path: str,
test_directory: str,
):
@click_merge_args_into_context_obj
@pass_pipeline_context
@click_ignore_unused_kwargs
async def test(pipeline_context: ClickPipelineContext):
"""Runs the tests for the given airbyte-ci package.

Args:
poetry_package_path (str): Path to the poetry package to test, relative to airbyte-ci directory.
test_directory (str): The directory containing the tests to run.
pipeline_context (ClickPipelineContext): The context object.
"""
success = await run_test(poetry_package_path, test_directory)
if not success:
click.Abort()
poetry_package_path = pipeline_context.params["poetry_package_path"]
test_directory = pipeline_context.params["test_directory"]

logger = logging.getLogger(f"{poetry_package_path}.tests")
logger.info(f"Running tests for {poetry_package_path}")

# The following directories are always mounted because a lot of tests rely on them
directories_to_always_mount = [".git", ".github", "docs", "airbyte-integrations", "airbyte-ci", "airbyte-cdk", "pyproject.toml"]
directories_to_mount = list(set([poetry_package_path, *directories_to_always_mount]))

pipeline_name = f"Unit tests for {poetry_package_path}"
dagger_client = await pipeline_context.get_dagger_client(pipeline_name=pipeline_name)
pytest_container = await (
dagger_client.container()
.from_("python:3.10.12")
.with_env_variable("PIPX_BIN_DIR", "/usr/local/bin")
.with_exec(
sh_dash_c(
[
"apt-get update",
"apt-get install -y bash git curl",
"pip install pipx",
"pipx ensurepath",
"pipx install poetry",
]
)
)
.with_env_variable("VERSION", DOCKER_VERSION)
.with_exec(sh_dash_c(["curl -fsSL https://get.docker.com | sh"]))
.with_mounted_directory(
"/airbyte",
dagger_client.host().directory(
".",
exclude=["**/__pycache__", "**/.pytest_cache", "**/.venv", "**.log", "**/.gradle"],
include=directories_to_mount,
),
)
.with_workdir(f"/airbyte/{poetry_package_path}")
.with_exec(["poetry", "install"])
.with_unix_socket("/var/run/docker.sock", dagger_client.host().unix_socket("/var/run/docker.sock"))
.with_exec(["poetry", "run", "pytest", test_directory])
)

await pytest_container
Loading
Loading