Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airbyte-ci: Allow airbyte-ci to run from anywhere in project #31412

Merged
merged 9 commits into from
Oct 19, 2023
1 change: 1 addition & 0 deletions airbyte-ci/connectors/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ This command runs the Python tests for a airbyte-ci poetry package.
## Changelog
| Version | PR | Description |
|---------| ---------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| 1.10.0 | [#31412](https://github.com/airbytehq/airbyte/pull/31412) | Run airbyte-ci from any where in airbyte project |
| 1.9.4 | [#31478](https://github.com/airbytehq/airbyte/pull/31478) | Fix running tests for connector-ops package. |
| 1.9.3 | [#31457](https://github.com/airbytehq/airbyte/pull/31457) | Improve the connector documentation for connectors migrated to our base image. |
| 1.9.2 | [#31426](https://github.com/airbytehq/airbyte/pull/31426) | Concurrent execution of java connectors tests. |
Expand Down
54 changes: 54 additions & 0 deletions airbyte-ci/connectors/pipelines/pipelines/commands/airbyte_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
"""This module is the CLI entrypoint to the airbyte-ci commands."""

import importlib
import logging
import os
from pathlib import Path
from typing import List

import click
import git
from github import PullRequest
from pipelines import github, main_logger
from pipelines.bases import CIContext
Expand Down Expand Up @@ -63,6 +67,55 @@ def get_latest_version() -> str:
raise Exception("Could not find version in pyproject.toml. Please ensure you are running from the root of the airbyte repo.")


def _validate_airbyte_repo(repo: git.Repo) -> bool:
"""Check if any of the remotes are the airbyte repo."""
expected_repo_name = "airbytehq/airbyte"
for remote in repo.remotes:
if expected_repo_name in remote.url:
return True

warning_message = f"""
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

It looks like you are not running this command from the airbyte repo ({expected_repo_name}).

If this command is run from outside the airbyte repo, it will not work properly.

Please run this command your local airbyte project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Please run this command your local airbyte project.
Please run this command in your local airbyte project.


⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
"""

logging.warning(warning_message)

return False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? Looks like the return value is not used



def get_airbyte_repo() -> git.Repo:
"""Get the airbyte repo."""
repo = git.Repo(search_parent_directories=True)
_validate_airbyte_repo(repo)
return repo


def get_airbyte_repo_path_with_fallback() -> Path:
"""Get the airbyte repo path."""
try:
return get_airbyte_repo().working_tree_dir
except git.exc.InvalidGitRepositoryError:
logging.warning("Could not find the airbyte repo, falling back to the current working directory.")
path = Path.cwd()
logging.warning(f"Using {path} as the airbyte repo path.")
return path


def set_working_directory_to_root() -> None:
"""Set the working directory to the root of the airbyte repo."""
working_dir = get_airbyte_repo_path_with_fallback()
logging.info(f"Setting working directory to {working_dir}")
os.chdir(working_dir)


def get_modified_files(
git_branch: str, git_revision: str, diffed_branch: str, is_local: bool, ci_context: CIContext, pull_request: PullRequest
) -> List[str]:
Expand Down Expand Up @@ -180,6 +233,7 @@ def airbyte_ci(
airbyte_ci.add_command(connectors)
airbyte_ci.add_command(metadata)
airbyte_ci.add_command(test)
set_working_directory_to_root()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably fine, but do any child-commands or forks need to be in a certain directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Currently every airbyte-ci command is imported here and every airbyte-ci logic assumes airbyte/ as the working directory.


if __name__ == "__main__":
airbyte_ci()
2 changes: 2 additions & 0 deletions airbyte-ci/connectors/pipelines/pipelines/dagger_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import pkg_resources
import requests
from pipelines.commands.airbyte_ci import set_working_directory_to_root

LOGGER = logging.getLogger(__name__)
BIN_DIR = Path.home() / "bin"
Expand Down Expand Up @@ -89,6 +90,7 @@ def check_dagger_cli_install() -> str:


def main():
set_working_directory_to_root()
os.environ[DAGGER_CLOUD_TOKEN_ENV_VAR_NAME_VALUE[0]] = DAGGER_CLOUD_TOKEN_ENV_VAR_NAME_VALUE[1]
exit_code = 0
if len(sys.argv) > 1 and any([arg in ARGS_DISABLING_TUI for arg in sys.argv]):
Expand Down
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 = "1.9.4"
version = "1.10.0"
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
authors = ["Airbyte <contact@airbyte.io>"]

Expand Down
Loading