|
1 | 1 | #
|
2 | 2 | # Copyright (c) 2023 Airbyte, Inc., all rights reserved.
|
3 | 3 | #
|
| 4 | +from __future__ import annotations |
4 | 5 |
|
5 | 6 | import logging
|
6 | 7 | from pathlib import Path
|
7 |
| -from typing import List |
| 8 | +from typing import TYPE_CHECKING |
8 | 9 |
|
9 | 10 | import asyncclick as click
|
| 11 | +import asyncer |
10 | 12 | from pipelines.cli.click_decorators import click_ignore_unused_kwargs, click_merge_args_into_context_obj
|
11 | 13 | from pipelines.consts import DOCKER_VERSION
|
12 | 14 | from pipelines.helpers.utils import sh_dash_c
|
13 | 15 | from pipelines.models.contexts.click_pipeline_context import ClickPipelineContext, pass_pipeline_context
|
14 | 16 |
|
| 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 | + |
15 | 36 |
|
16 | 37 | @click.command()
|
17 | 38 | @click.argument("poetry_package_path")
|
@@ -89,6 +110,15 @@ async def test(pipeline_context: ClickPipelineContext):
|
89 | 110 | .with_env_variable("CI", str(pipeline_context.params["is_ci"]))
|
90 | 111 | .with_workdir(f"/airbyte/{poetry_package_path}")
|
91 | 112 | )
|
92 |
| - for command in commands_to_run: |
93 |
| - test_container = test_container.with_exec(["poetry", "run", *command.split(" ")]) |
94 |
| - await test_container |
| 113 | + |
| 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) |
0 commit comments