Skip to content

Commit

Permalink
airbyte-ci: make airbyte-ci test able to run any poetry run command
Browse files Browse the repository at this point in the history
  • Loading branch information
alafanechere committed Dec 26, 2023
1 parent bfe9d8b commit ab794c1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/airbyte-ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
gcs_credentials: ${{ secrets.METADATA_SERVICE_PROD_GCS_CREDENTIALS }}
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
github_token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }}
subcommand: "test airbyte-ci/connectors/connector_ops"
subcommand: "test airbyte-ci/connectors/connector_ops --poetry-run-command='pytest tests'"
airbyte_ci_binary_url: ${{ inputs.airbyte_ci_binary_url || 'https://connectors.airbyte.com/airbyte-ci/releases/ubuntu/latest/airbyte-ci' }}
tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }}

Expand All @@ -88,7 +88,7 @@ jobs:
gcs_credentials: ${{ secrets.METADATA_SERVICE_PROD_GCS_CREDENTIALS }}
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
github_token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }}
subcommand: "test airbyte-ci/connectors/pipelines"
subcommand: "test airbyte-ci/connectors/pipelines --poetry-run-command='pytest tests'"
airbyte_ci_binary_url: ${{ inputs.airbyte_ci_binary_url || 'https://connectors.airbyte.com/airbyte-ci/releases/ubuntu/latest/airbyte-ci' }}
tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }}

Expand All @@ -103,7 +103,7 @@ jobs:
gcs_credentials: ${{ secrets.METADATA_SERVICE_PROD_GCS_CREDENTIALS }}
sentry_dsn: ${{ secrets.SENTRY_AIRBYTE_CI_DSN }}
github_token: ${{ secrets.GH_PAT_MAINTENANCE_OCTAVIA }}
subcommand: "test airbyte-ci/connectors/base_images"
subcommand: "test airbyte-ci/connectors/base_images --poetry-run-command='pytest tests'"
airbyte_ci_binary_url: ${{ inputs.airbyte_ci_binary_url || 'https://connectors.airbyte.com/airbyte-ci/releases/ubuntu/latest/airbyte-ci' }}
tailscale_auth_key: ${{ secrets.TAILSCALE_AUTH_KEY }}

Expand All @@ -112,7 +112,7 @@ jobs:
if: steps.changes.outputs.metadata_lib_any_changed == 'true'
uses: ./.github/actions/run-dagger-pipeline
with:
subcommand: "test airbyte-ci/connectors/metadata_service/lib/"
subcommand: "test airbyte-ci/connectors/metadata_service/lib/ --poetry-run-command='pytest tests'"
context: "pull_request"
github_token: ${{ secrets.GITHUB_TOKEN }}
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}
Expand All @@ -125,7 +125,7 @@ jobs:
if: steps.changes.outputs.metadata_orchestrator_any_changed == 'true'
uses: ./.github/actions/run-dagger-pipeline
with:
subcommand: "test airbyte-ci/connectors/metadata_service/orchestrator/"
subcommand: "test airbyte-ci/connectors/metadata_service/orchestrator/ --poetry-run-command='pytest tests'"
context: "pull_request"
github_token: ${{ secrets.GITHUB_TOKEN }}
docker_hub_username: ${{ secrets.DOCKER_HUB_USERNAME }}
Expand Down
8 changes: 5 additions & 3 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,19 @@ This command runs the Python tests for a airbyte-ci poetry package.

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

#### Example

`airbyte-ci test airbyte-ci/connectors/pipelines --test-directory=tests`
`airbyte-ci tests airbyte-integrations/bases/connector-acceptance-test --test-directory=unit_tests`
`airbyte-ci test airbyte-ci/connectors/pipelines --poetry-run-command='pytest tests'`
`airbyte-ci tests airbyte-integrations/bases/connector-acceptance-test--poetry-run-command='pytest tests/unit_tests'`

## Changelog

| Version | PR | Description |
| ------- | ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| 2.13.0 | [#33784](https://github.com/airbytehq/airbyte/pull/33784) | Make `airbyte-ci test` able to run any poetry command |
| 2.12.0 | [#33313](https://github.com/airbytehq/airbyte/pull/33313) | Add upgrade CDK command |
| 2.11.0 | [#32188](https://github.com/airbytehq/airbyte/pull/32188) | Add -x option to connector test to allow for skipping steps |
| 2.10.12 | [#33419](https://github.com/airbytehq/airbyte/pull/33419) | Make ClickPipelineContext handle dagger logging. |
| 2.10.11 | [#33497](https://github.com/airbytehq/airbyte/pull/33497) | Consider nested .gitignore rules in format. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#

import logging
from pathlib import Path
from typing import List

import asyncclick as click
from pipelines.cli.click_decorators import click_ignore_unused_kwargs, click_merge_args_into_context_obj
Expand All @@ -13,7 +15,13 @@

@click.command()
@click.argument("poetry_package_path")
@click.option("--test-directory", default="tests", help="The directory containing the tests to run.")
@click.option(
"-c",
"--poetry-run-command",
multiple=True,
help="The poetry run command to run.",
required=True,
)
@click_merge_args_into_context_obj
@pass_pipeline_context
@click_ignore_unused_kwargs
Expand All @@ -24,7 +32,10 @@ async def test(pipeline_context: ClickPipelineContext):
pipeline_context (ClickPipelineContext): The context object.
"""
poetry_package_path = pipeline_context.params["poetry_package_path"]
test_directory = pipeline_context.params["test_directory"]
if not Path(f"{poetry_package_path}/pyproject.toml").exists():
raise click.UsageError(f"Could not find pyproject.toml in {poetry_package_path}")

commands_to_run: List[str] = pipeline_context.params["poetry_run_command"]

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

pipeline_name = f"Unit tests for {poetry_package_path}"
dagger_client = await pipeline_context.get_dagger_client(pipeline_name=pipeline_name)
pytest_container = await (
test_container = await (
dagger_client.container()
.from_("python:3.10.12")
.with_env_variable("PIPX_BIN_DIR", "/usr/local/bin")
Expand All @@ -73,10 +84,11 @@ async def test(pipeline_context: ClickPipelineContext):
),
)
.with_workdir(f"/airbyte/{poetry_package_path}")
.with_exec(["poetry", "install"])
.with_exec(["poetry", "install", "--with=dev"])
.with_unix_socket("/var/run/docker.sock", dagger_client.host().unix_socket("/var/run/docker.sock"))
.with_env_variable("CI", str(pipeline_context.params["is_ci"]))
.with_exec(["poetry", "run", "pytest", test_directory])
.with_workdir(f"/airbyte/{poetry_package_path}")
)

await pytest_container
for command in commands_to_run:
test_container = test_container.with_exec(["poetry", "run", *command.split(" ")])
await test_container
2 changes: 1 addition & 1 deletion airbyte-ci/connectors/pipelines/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "pipelines"
version = "2.12.0"
version = "2.13.0"
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
authors = ["Airbyte <contact@airbyte.io>"]

Expand Down

0 comments on commit ab794c1

Please sign in to comment.