forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Airbyte-ci: Ensure we set the working directory earlier (airbytehq#34136
- Loading branch information
1 parent
fa30edb
commit 9656c4e
Showing
4 changed files
with
65 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
airbyte-ci/connectors/pipelines/pipelines/cli/ensure_repo_root.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
import os | ||
from pathlib import Path | ||
|
||
import git | ||
|
||
|
||
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 | ||
|
||
|
||
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 path to the airbyte repo.""" | ||
try: | ||
repo_path = get_airbyte_repo().working_tree_dir | ||
if repo_path is not None: | ||
return Path(str(get_airbyte_repo().working_tree_dir)) | ||
except git.exc.InvalidGitRepositoryError: | ||
pass | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters