Skip to content

Commit c37f25f

Browse files
alafanechereerohmensing
authored andcommitted
airbyte-ci: make airbyte-ci test able to run any poetry run command (airbytehq#33784)
Co-authored-by: Ella Rohm-Ensing <[email protected]>
1 parent 0ba82b6 commit c37f25f

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

.github/workflows/airbyte-ci-tests.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
gcs_credentials: ${{ secrets.METADATA_SERVICE_PROD_GCS_CREDENTIALS }}
7777
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
7878
github_token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }}
79-
subcommand: "test airbyte-ci/connectors/connector_ops"
79+
subcommand: "test airbyte-ci/connectors/connector_ops --poetry-run-command='pytest tests'"
8080
airbyte_ci_binary_url: ${{ inputs.airbyte_ci_binary_url || 'https://connectors.airbyte.com/airbyte-ci/releases/ubuntu/latest/airbyte-ci' }}
8181
tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }}
8282

@@ -91,7 +91,7 @@ jobs:
9191
gcs_credentials: ${{ secrets.METADATA_SERVICE_PROD_GCS_CREDENTIALS }}
9292
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
9393
github_token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }}
94-
subcommand: "test airbyte-ci/connectors/pipelines"
94+
subcommand: "test airbyte-ci/connectors/pipelines --poetry-run-command='pytest tests'"
9595
airbyte_ci_binary_url: ${{ inputs.airbyte_ci_binary_url || 'https://connectors.airbyte.com/airbyte-ci/releases/ubuntu/latest/airbyte-ci' }}
9696
tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }}
9797

@@ -106,7 +106,7 @@ jobs:
106106
gcs_credentials: ${{ secrets.METADATA_SERVICE_PROD_GCS_CREDENTIALS }}
107107
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
108108
github_token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }}
109-
subcommand: "test airbyte-ci/connectors/base_images"
109+
subcommand: "test airbyte-ci/connectors/base_images --poetry-run-command='pytest tests'"
110110
airbyte_ci_binary_url: ${{ inputs.airbyte_ci_binary_url || 'https://connectors.airbyte.com/airbyte-ci/releases/ubuntu/latest/airbyte-ci' }}
111111
tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }}
112112

@@ -115,7 +115,7 @@ jobs:
115115
if: steps.changes.outputs.metadata_lib_any_changed == 'true'
116116
uses: ./.github/actions/run-dagger-pipeline
117117
with:
118-
subcommand: "test airbyte-ci/connectors/metadata_service/lib/"
118+
subcommand: "test airbyte-ci/connectors/metadata_service/lib/ --poetry-run-command='pytest tests'"
119119
context: "pull_request"
120120
github_token: ${{ secrets.GITHUB_TOKEN }}
121121
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}
@@ -128,7 +128,7 @@ jobs:
128128
if: steps.changes.outputs.metadata_orchestrator_any_changed == 'true'
129129
uses: ./.github/actions/run-dagger-pipeline
130130
with:
131-
subcommand: "test airbyte-ci/connectors/metadata_service/orchestrator/"
131+
subcommand: "test airbyte-ci/connectors/metadata_service/orchestrator/ --poetry-run-command='pytest tests'"
132132
context: "pull_request"
133133
github_token: ${{ secrets.GITHUB_TOKEN }}
134134
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}

airbyte-ci/connectors/pipelines/README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,23 @@ This command runs the Python tests for a airbyte-ci poetry package.
506506

507507
| Option | Required | Default | Mapped environment variable | Description |
508508
| ------------------ | -------- | ------- | --------------------------- | ------------------------------------------------------------------------------------------------ |
509-
| `--test-directory` | False | tests | | The path to the directory on which pytest should discover tests, relative to the poetry package. |
509+
| `-c/--poetry-run-command` | True | None | | The command to run with `poetry run` |
510510

511-
#### Example
511+
#### Examples
512+
You can pass multiple `-c/--poetry-run-command` options to run multiple commands.
513+
514+
E.G.: running `pytest` and `mypy`:
515+
`airbyte-ci test airbyte-ci/connectors/pipelines --poetry-run-command='pytest tests' --poetry-run-command='mypy pipelines'`
512516

513-
`airbyte-ci test airbyte-ci/connectors/pipelines --test-directory=tests`
514-
`airbyte-ci tests airbyte-integrations/bases/connector-acceptance-test --test-directory=unit_tests`
517+
E.G.: running `pytest` on a specific test folder:
518+
`airbyte-ci tests airbyte-integrations/bases/connector-acceptance-test --poetry-run-command='pytest tests/unit_tests'`
515519

516520
## Changelog
517521

518522
| Version | PR | Description |
519523
| ------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
524+
| 2.13.0 | [#33784](https://github.com/airbytehq/airbyte/pull/33784) | Make `airbyte-ci test` able to run any poetry command |
525+
| 2.12.0 | [#33313](https://github.com/airbytehq/airbyte/pull/33313) | Add upgrade CDK command |
520526
| 2.11.0 | [#32188](https://github.com/airbytehq/airbyte/pull/32188) | Add -x option to connector test to allow for skipping steps |
521527
| 2.10.12 | [#33419](https://github.com/airbytehq/airbyte/pull/33419) | Make ClickPipelineContext handle dagger logging. |
522528
| 2.10.11 | [#33497](https://github.com/airbytehq/airbyte/pull/33497) | Consider nested .gitignore rules in format. |

airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/test/commands.py

+48-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
11
#
22
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#
4+
from __future__ import annotations
45

56
import logging
7+
from pathlib import Path
8+
from typing import TYPE_CHECKING
69

710
import asyncclick as click
11+
import asyncer
812
from pipelines.cli.click_decorators import click_ignore_unused_kwargs, click_merge_args_into_context_obj
913
from pipelines.consts import DOCKER_VERSION
1014
from pipelines.helpers.utils import sh_dash_c
1115
from pipelines.models.contexts.click_pipeline_context import ClickPipelineContext, pass_pipeline_context
1216

17+
if TYPE_CHECKING:
18+
from typing import List, Tuple
19+
20+
import dagger
21+
22+
## HELPERS
23+
async def run_poetry_command(container: dagger.Container, command: str) -> Tuple[str, str]:
24+
"""Run a poetry command in a container and return the stdout and stderr.
25+
26+
Args:
27+
container (dagger.Container): The container to run the command in.
28+
command (str): The command to run.
29+
30+
Returns:
31+
Tuple[str, str]: The stdout and stderr of the command.
32+
"""
33+
container = container.with_exec(["poetry", "run", *command.split(" ")])
34+
return await container.stdout(), await container.stderr()
35+
1336

1437
@click.command()
1538
@click.argument("poetry_package_path")
16-
@click.option("--test-directory", default="tests", help="The directory containing the tests to run.")
39+
@click.option(
40+
"-c",
41+
"--poetry-run-command",
42+
multiple=True,
43+
help="The poetry run command to run.",
44+
required=True,
45+
)
1746
@click_merge_args_into_context_obj
1847
@pass_pipeline_context
1948
@click_ignore_unused_kwargs
@@ -24,7 +53,10 @@ async def test(pipeline_context: ClickPipelineContext):
2453
pipeline_context (ClickPipelineContext): The context object.
2554
"""
2655
poetry_package_path = pipeline_context.params["poetry_package_path"]
27-
test_directory = pipeline_context.params["test_directory"]
56+
if not Path(f"{poetry_package_path}/pyproject.toml").exists():
57+
raise click.UsageError(f"Could not find pyproject.toml in {poetry_package_path}")
58+
59+
commands_to_run: List[str] = pipeline_context.params["poetry_run_command"]
2860

2961
logger = logging.getLogger(f"{poetry_package_path}.tests")
3062
logger.info(f"Running tests for {poetry_package_path}")
@@ -47,7 +79,7 @@ async def test(pipeline_context: ClickPipelineContext):
4779

4880
pipeline_name = f"Unit tests for {poetry_package_path}"
4981
dagger_client = await pipeline_context.get_dagger_client(pipeline_name=pipeline_name)
50-
pytest_container = await (
82+
test_container = await (
5183
dagger_client.container()
5284
.from_("python:3.10.12")
5385
.with_env_variable("PIPX_BIN_DIR", "/usr/local/bin")
@@ -73,10 +105,20 @@ async def test(pipeline_context: ClickPipelineContext):
73105
),
74106
)
75107
.with_workdir(f"/airbyte/{poetry_package_path}")
76-
.with_exec(["poetry", "install"])
108+
.with_exec(["poetry", "install", "--with=dev"])
77109
.with_unix_socket("/var/run/docker.sock", dagger_client.host().unix_socket("/var/run/docker.sock"))
78110
.with_env_variable("CI", str(pipeline_context.params["is_ci"]))
79-
.with_exec(["poetry", "run", "pytest", test_directory])
111+
.with_workdir(f"/airbyte/{poetry_package_path}")
80112
)
81113

82-
await pytest_container
114+
soon_command_executions_results = []
115+
async with asyncer.create_task_group() as poetry_commands_task_group:
116+
for command in commands_to_run:
117+
logger.info(f"Running command: {command}")
118+
soon_command_execution_result = poetry_commands_task_group.soonify(run_poetry_command)(test_container, command)
119+
soon_command_executions_results.append(soon_command_execution_result)
120+
121+
for result in soon_command_executions_results:
122+
stdout, stderr = result.value
123+
logger.info(stdout)
124+
logger.error(stderr)

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 = "2.12.0"
7+
version = "2.13.0"
88
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
99
authors = ["Airbyte <[email protected]>"]
1010

0 commit comments

Comments
 (0)