Skip to content

Commit e669832

Browse files
authored
airbyte-ci: dynamic test step tree according to metadata (#38281)
1 parent e5a390d commit e669832

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

airbyte-ci/connectors/pipelines/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,14 @@ flowchart TD
298298
#### Options
299299

300300
| Option | Multiple | Default value | Description |
301-
| ------------------------------------------------------- | -------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
301+
| ------------------------------------------------------- | -------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
302302
| `--skip-step/-x` | True | | Skip steps by id e.g. `-x unit -x acceptance` |
303303
| `--only-step/-k` | True | | Only run specific steps by id e.g. `-k unit -k acceptance` |
304304
| `--fail-fast` | False | False | Abort after any tests fail, rather than continuing to run additional tests. Use this setting to confirm a known bug is fixed (or not), or when you only require a pass/fail result. |
305305
| `--code-tests-only` | True | False | Skip any tests not directly related to code updates. For instance, metadata checks, version bump checks, changelog verification, etc. Use this setting to help focus on code quality during development. |
306306
| `--concurrent-cat` | False | False | Make CAT tests run concurrently using pytest-xdist. Be careful about source or destination API rate limits. |
307307
| `--<step-id>.<extra-parameter>=<extra-parameter-value>` | True | | You can pass extra parameters for specific test steps. More details in the extra parameters section below |
308-
| `--ci-requirements` | False | | | Output the CI requirements as a JSON payload. It is used to determine the CI runner to use. |
308+
| `--ci-requirements` | False | | | Output the CI requirements as a JSON payload. It is used to determine the CI runner to use.
309309

310310
Note:
311311

@@ -745,6 +745,7 @@ E.G.: running Poe tasks on the modified internal packages of the current branch:
745745

746746
| Version | PR | Description |
747747
|---------|------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
748+
| 4.14.0 | [#38281](https://github.com/airbytehq/airbyte/pull/38281) | Conditionally run test suites according to `connectorTestSuitesOptions` in metadata files. |
748749
| 4.13.3 | [#38221](https://github.com/airbytehq/airbyte/pull/38221) | Add dagster cloud dev deployment pipeline opitions |
749750
| 4.13.2 | [#38246](https://github.com/airbytehq/airbyte/pull/38246) | Remove invalid connector test step options. |
750751
| 4.13.1 | [#38020](https://github.com/airbytehq/airbyte/pull/38020) | Add `auto_merge` as an internal package to test. |

airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/connectors/context.py

+35-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from __future__ import annotations
88

9+
from copy import deepcopy
910
from datetime import datetime
1011
from pathlib import Path
1112
from types import TracebackType
@@ -15,6 +16,7 @@
1516
from asyncer import asyncify
1617
from dagger import Directory, Platform, Secret
1718
from github import PullRequest
19+
from pipelines.airbyte_ci.connectors.consts import CONNECTOR_TEST_STEP_ID
1820
from pipelines.airbyte_ci.connectors.reports import ConnectorReport
1921
from pipelines.consts import BUILD_PLATFORMS
2022
from pipelines.dagger.actions import secrets
@@ -29,6 +31,13 @@
2931
from pathlib import Path as NativePath
3032
from typing import Dict, FrozenSet, List, Optional, Sequence
3133

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+
3241

3342
class ConnectorContext(PipelineContext):
3443
"""The connector context is used to store configuration for a specific connector pipeline run."""
@@ -140,7 +149,7 @@ def __init__(
140149
ci_gcs_credentials=ci_gcs_credentials,
141150
ci_git_user=ci_git_user,
142151
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),
144153
enable_report_auto_open=enable_report_auto_open,
145154
)
146155

@@ -286,3 +295,28 @@ async def __aexit__(
286295

287296
def create_slack_message(self) -> str:
288297
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

airbyte-ci/connectors/pipelines/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pipelines"
7-
version = "4.13.3"
7+
version = "4.14.0"
88
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
99
authors = ["Airbyte <[email protected]>"]
1010

airbyte-ci/connectors/pipelines/tests/test_actions/test_environments.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#
44

5-
import asyncclick as click
65
import pytest
76
from pipelines.airbyte_ci.connectors.context import ConnectorContext
87
from pipelines.dagger.actions.python import common
8+
from pipelines.helpers.connectors.modifed import ConnectorWithModifiedFiles
99

1010
pytestmark = [
1111
pytest.mark.anyio,
@@ -16,7 +16,7 @@
1616
def connector_context(dagger_client):
1717
context = ConnectorContext(
1818
pipeline_name="test",
19-
connector="source-faker",
19+
connector=ConnectorWithModifiedFiles("source-faker", modified_files={}),
2020
git_branch="test",
2121
git_revision="test",
2222
diffed_branch="test",

0 commit comments

Comments
 (0)