-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Changes from 5 commits
0575c53
28424b7
6746edb
7dc9d32
643241c
d11c076
50f85f3
512b6da
619eebe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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. | ||
|
||
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️ | ||
""" | ||
|
||
logging.warning(warning_message) | ||
|
||
return False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]: | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope. Currently every |
||
|
||
if __name__ == "__main__": | ||
airbyte_ci() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.