|
| 1 | +# |
| 2 | +# Copyright (c) 2023 Airbyte, Inc., all rights reserved. |
| 3 | +# |
| 4 | + |
| 5 | +from typing import Dict, List |
| 6 | + |
| 7 | +import asyncclick as click |
| 8 | +from pipelines import main_logger |
| 9 | +from pipelines.airbyte_ci.connectors.consts import CONNECTOR_TEST_STEP_ID |
| 10 | +from pipelines.airbyte_ci.connectors.context import ConnectorContext |
| 11 | +from pipelines.airbyte_ci.connectors.pipeline import run_connectors_pipelines |
| 12 | +from pipelines.airbyte_ci.connectors.regression_test.pipeline import run_connector_regression_test_pipeline |
| 13 | +from pipelines.cli.click_decorators import click_ci_requirements_option |
| 14 | +from pipelines.cli.dagger_pipeline_command import DaggerPipelineCommand |
| 15 | +from pipelines.consts import LOCAL_BUILD_PLATFORM, ContextState |
| 16 | +from pipelines.helpers.execution import argument_parsing |
| 17 | +from pipelines.helpers.execution.run_steps import RunStepOptions |
| 18 | +from pipelines.helpers.github import update_global_commit_status_check_for_tests |
| 19 | +from pipelines.helpers.utils import fail_if_missing_docker_hub_creds |
| 20 | +from pipelines.models.steps import STEP_PARAMS |
| 21 | + |
| 22 | + |
| 23 | +@click.command( |
| 24 | + cls=DaggerPipelineCommand, |
| 25 | + help="Test all the selected connectors.", |
| 26 | + context_settings=dict( |
| 27 | + ignore_unknown_options=True, |
| 28 | + ), |
| 29 | +) |
| 30 | +@click_ci_requirements_option() |
| 31 | +@click.option( |
| 32 | + "--control-version", |
| 33 | + help=( |
| 34 | + "Control version of the connector to be tested. Records will be downloaded from this container and used as expected records for the target version." |
| 35 | + ), |
| 36 | + default="latest", |
| 37 | + type=str, |
| 38 | +) |
| 39 | +@click.option( |
| 40 | + "--target-version", |
| 41 | + help=("Target version of the connector being tested."), |
| 42 | + default="dev", |
| 43 | + type=str, |
| 44 | +) |
| 45 | +@click.option( |
| 46 | + "--fail-fast", |
| 47 | + help="When enabled, tests will fail fast.", |
| 48 | + default=False, |
| 49 | + type=bool, |
| 50 | + is_flag=True, |
| 51 | +) |
| 52 | +@click.pass_context |
| 53 | +async def regression_test(ctx: click.Context, control_version: str, target_version: str, fail_fast: bool) -> bool: |
| 54 | + """ |
| 55 | + Runs a regression test pipeline for the selected connectors. |
| 56 | + """ |
| 57 | + if ctx.obj["is_ci"]: |
| 58 | + fail_if_missing_docker_hub_creds(ctx) |
| 59 | + |
| 60 | + if ctx.obj["selected_connectors_with_modified_files"]: |
| 61 | + update_global_commit_status_check_for_tests(ctx.obj, "pending") |
| 62 | + else: |
| 63 | + main_logger.warn("No connector were selected for testing.") |
| 64 | + update_global_commit_status_check_for_tests(ctx.obj, "success") |
| 65 | + return True |
| 66 | + |
| 67 | + run_step_options = RunStepOptions(fail_fast=fail_fast) |
| 68 | + connectors_tests_contexts = [] |
| 69 | + for connector in ctx.obj["selected_connectors_with_modified_files"]: |
| 70 | + if control_version in ("dev", "latest"): |
| 71 | + control_version = f"airbyte/{connector.technical_name}:{control_version}" |
| 72 | + |
| 73 | + if target_version in ("dev", "latest"): |
| 74 | + target_version = f"airbyte/{connector.technical_name}:{target_version}" |
| 75 | + |
| 76 | + connectors_tests_contexts.append( |
| 77 | + ConnectorContext( |
| 78 | + pipeline_name=f"Testing connector {connector.technical_name}", |
| 79 | + connector=connector, |
| 80 | + is_local=ctx.obj["is_local"], |
| 81 | + git_branch=ctx.obj["git_branch"], |
| 82 | + git_revision=ctx.obj["git_revision"], |
| 83 | + ci_report_bucket=ctx.obj["ci_report_bucket_name"], |
| 84 | + report_output_prefix=ctx.obj["report_output_prefix"], |
| 85 | + use_remote_secrets=ctx.obj["use_remote_secrets"], |
| 86 | + gha_workflow_run_url=ctx.obj.get("gha_workflow_run_url"), |
| 87 | + dagger_logs_url=ctx.obj.get("dagger_logs_url"), |
| 88 | + pipeline_start_timestamp=ctx.obj.get("pipeline_start_timestamp"), |
| 89 | + ci_context=ctx.obj.get("ci_context"), |
| 90 | + pull_request=ctx.obj.get("pull_request"), |
| 91 | + ci_gcs_credentials=ctx.obj["ci_gcs_credentials"], |
| 92 | + use_local_cdk=ctx.obj.get("use_local_cdk"), |
| 93 | + s3_build_cache_access_key_id=ctx.obj.get("s3_build_cache_access_key_id"), |
| 94 | + s3_build_cache_secret_key=ctx.obj.get("s3_build_cache_secret_key"), |
| 95 | + docker_hub_username=ctx.obj.get("docker_hub_username"), |
| 96 | + docker_hub_password=ctx.obj.get("docker_hub_password"), |
| 97 | + run_step_options=run_step_options, |
| 98 | + targeted_platforms=[LOCAL_BUILD_PLATFORM], |
| 99 | + versions_to_test=(control_version, target_version), |
| 100 | + ) |
| 101 | + ) |
| 102 | + |
| 103 | + try: |
| 104 | + await run_connectors_pipelines( |
| 105 | + [connector_context for connector_context in connectors_tests_contexts], |
| 106 | + run_connector_regression_test_pipeline, |
| 107 | + "Regression Test Pipeline", |
| 108 | + ctx.obj["concurrency"], |
| 109 | + ctx.obj["dagger_logs_path"], |
| 110 | + ctx.obj["execute_timeout"], |
| 111 | + ) |
| 112 | + except Exception as e: |
| 113 | + main_logger.error("An error occurred while running the regression test pipeline", exc_info=e) |
| 114 | + return False |
| 115 | + |
| 116 | + return True |
0 commit comments