|
6 | 6 |
|
7 | 7 | from __future__ import annotations
|
8 | 8 |
|
| 9 | +from copy import deepcopy |
9 | 10 | from datetime import datetime
|
10 | 11 | from pathlib import Path
|
11 | 12 | from types import TracebackType
|
|
15 | 16 | from asyncer import asyncify
|
16 | 17 | from dagger import Directory, Platform, Secret
|
17 | 18 | from github import PullRequest
|
| 19 | +from pipelines.airbyte_ci.connectors.consts import CONNECTOR_TEST_STEP_ID |
18 | 20 | from pipelines.airbyte_ci.connectors.reports import ConnectorReport
|
19 | 21 | from pipelines.consts import BUILD_PLATFORMS
|
20 | 22 | from pipelines.dagger.actions import secrets
|
|
29 | 31 | from pathlib import Path as NativePath
|
30 | 32 | from typing import Dict, FrozenSet, List, Optional, Sequence
|
31 | 33 |
|
| 34 | +# These test suite names are declared in metadata.yaml files |
| 35 | +TEST_SUITE_NAME_TO_STEP_ID = { |
| 36 | + "unitTests": CONNECTOR_TEST_STEP_ID.UNIT, |
| 37 | + "integrationTests": CONNECTOR_TEST_STEP_ID.INTEGRATION, |
| 38 | + "acceptanceTests": CONNECTOR_TEST_STEP_ID.ACCEPTANCE, |
| 39 | +} |
| 40 | + |
32 | 41 |
|
33 | 42 | class ConnectorContext(PipelineContext):
|
34 | 43 | """The connector context is used to store configuration for a specific connector pipeline run."""
|
@@ -140,7 +149,7 @@ def __init__(
|
140 | 149 | ci_gcs_credentials=ci_gcs_credentials,
|
141 | 150 | ci_git_user=ci_git_user,
|
142 | 151 | ci_github_access_token=ci_github_access_token,
|
143 |
| - run_step_options=run_step_options, |
| 152 | + run_step_options=self._skip_metadata_disabled_test_suites(run_step_options), |
144 | 153 | enable_report_auto_open=enable_report_auto_open,
|
145 | 154 | )
|
146 | 155 |
|
@@ -286,3 +295,28 @@ async def __aexit__(
|
286 | 295 |
|
287 | 296 | def create_slack_message(self) -> str:
|
288 | 297 | raise NotImplementedError
|
| 298 | + |
| 299 | + def _get_step_id_to_skip_according_to_metadata(self) -> List[CONNECTOR_TEST_STEP_ID]: |
| 300 | + """The connector metadata have a connectorTestSuitesOptions field. |
| 301 | + It allows connector developers to declare the test suites that are enabled for a connector. |
| 302 | + This function retrieved enabled test suites according to this field value and returns the test suites steps that are skipped (because they're not declared in this field.) |
| 303 | + The skippable test suites steps are declared in TEST_SUITE_NAME_TO_STEP_ID. |
| 304 | +
|
| 305 | + Returns: |
| 306 | + List[CONNECTOR_TEST_STEP_ID]: List of step ids that should be skipped according to connector metadata. |
| 307 | + """ |
| 308 | + enabled_test_suites = [option["suite"] for option in self.metadata.get("connectorTestSuitesOptions", [])] |
| 309 | + return [step_id for test_suite_name, step_id in TEST_SUITE_NAME_TO_STEP_ID.items() if test_suite_name not in enabled_test_suites] |
| 310 | + |
| 311 | + def _skip_metadata_disabled_test_suites(self, run_step_options: RunStepOptions) -> RunStepOptions: |
| 312 | + """Updated the original run_step_options to skip the disabled test suites according to connector metadata. |
| 313 | +
|
| 314 | + Args: |
| 315 | + run_step_options (RunStepOptions): Original run step options. |
| 316 | +
|
| 317 | + Returns: |
| 318 | + RunStepOptions: Updated run step options. |
| 319 | + """ |
| 320 | + run_step_options = deepcopy(run_step_options) |
| 321 | + run_step_options.skip_steps += self._get_step_id_to_skip_according_to_metadata() |
| 322 | + return run_step_options |
0 commit comments