From 4b7c308f91d695c3f2e4894e3f6418b1419e9bc0 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Wed, 27 Apr 2022 21:47:16 +0200 Subject: [PATCH] Fix retrieval of the right branch in pre-commits (#23297) (cherry picked from commit d93908deb7bfea2bc7cfe5a69830b01e4df06676) --- scripts/ci/pre_commit/pre_commit_flake8.py | 6 +++++- scripts/ci/pre_commit/pre_commit_migration_reference.py | 5 ++++- scripts/ci/pre_commit/pre_commit_mypy.py | 7 ++++++- scripts/ci/pre_commit/pre_commit_ui_lint.py | 4 ++++ scripts/ci/pre_commit/pre_commit_www_lint.py | 4 ++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/scripts/ci/pre_commit/pre_commit_flake8.py b/scripts/ci/pre_commit/pre_commit_flake8.py index 163154ba47f8c..19841b3347420 100755 --- a/scripts/ci/pre_commit/pre_commit_flake8.py +++ b/scripts/ci/pre_commit/pre_commit_flake8.py @@ -30,9 +30,13 @@ AIRFLOW_SOURCES = Path(__file__).parents[3].absolute() GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', "apache/airflow") -AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/main/ci/python3.7" if __name__ == '__main__': + sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src")) + from airflow_breeze.branch_defaults import AIRFLOW_BRANCH + + AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7" + if subprocess.call(args=["docker", "inspect", AIRFLOW_CI_IMAGE], stdout=subprocess.DEVNULL) != 0: print(f'[red]The image {AIRFLOW_CI_IMAGE} is not available.[/]\n') print("\n[yellow]Please run at the earliest convenience:[/]\n\nbreeze build-image --python 3.7\n\n") diff --git a/scripts/ci/pre_commit/pre_commit_migration_reference.py b/scripts/ci/pre_commit/pre_commit_migration_reference.py index a0a0b7bed01a5..6e1fc15c198f6 100755 --- a/scripts/ci/pre_commit/pre_commit_migration_reference.py +++ b/scripts/ci/pre_commit/pre_commit_migration_reference.py @@ -30,9 +30,12 @@ AIRFLOW_SOURCES = Path(__file__).parents[3].absolute() GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', "apache/airflow") -AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/main/ci/python3.7" if __name__ == '__main__': + sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src")) + from airflow_breeze.branch_defaults import AIRFLOW_BRANCH + + AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7" if subprocess.call(args=["docker", "inspect", AIRFLOW_CI_IMAGE], stdout=subprocess.DEVNULL) != 0: print(f'[red]The image {AIRFLOW_CI_IMAGE} is not available.[/]\n') print("\n[yellow]Please run at the earliest convenience:[/]\n\nbreeze build-image --python 3.7\n\n") diff --git a/scripts/ci/pre_commit/pre_commit_mypy.py b/scripts/ci/pre_commit/pre_commit_mypy.py index 93ff218f941d7..0c70b96d52a54 100755 --- a/scripts/ci/pre_commit/pre_commit_mypy.py +++ b/scripts/ci/pre_commit/pre_commit_mypy.py @@ -28,11 +28,16 @@ f"To run this script, run the ./{__file__} command" ) + AIRFLOW_SOURCES = Path(__file__).parents[3].absolute() GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', "apache/airflow") -AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/main/ci/python3.7" if __name__ == '__main__': + sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src")) + from airflow_breeze.branch_defaults import AIRFLOW_BRANCH + + AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7" + if subprocess.call(args=["docker", "inspect", AIRFLOW_CI_IMAGE], stdout=subprocess.DEVNULL) != 0: print(f'[red]The image {AIRFLOW_CI_IMAGE} is not available.[/]\n') print("\n[yellow]Please run at the earliest convenience:[/]\n\nbreeze build-image --python 3.7\n\n") diff --git a/scripts/ci/pre_commit/pre_commit_ui_lint.py b/scripts/ci/pre_commit/pre_commit_ui_lint.py index ab29d9707c426..45360faa85ef5 100755 --- a/scripts/ci/pre_commit/pre_commit_ui_lint.py +++ b/scripts/ci/pre_commit/pre_commit_ui_lint.py @@ -33,6 +33,10 @@ AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/main/ci/python3.7" if __name__ == '__main__': + sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src")) + from airflow_breeze.branch_defaults import AIRFLOW_BRANCH + + AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7" if subprocess.call(args=["docker", "inspect", AIRFLOW_CI_IMAGE], stdout=subprocess.DEVNULL) != 0: print(f'[red]The image {AIRFLOW_CI_IMAGE} is not available.[/]\n') print("\n[yellow]Please run at the earliest convenience:[/]\n\nbreeze build-image --python 3.7\n\n") diff --git a/scripts/ci/pre_commit/pre_commit_www_lint.py b/scripts/ci/pre_commit/pre_commit_www_lint.py index 2e64f4a54cf41..5e0d1f83aba72 100755 --- a/scripts/ci/pre_commit/pre_commit_www_lint.py +++ b/scripts/ci/pre_commit/pre_commit_www_lint.py @@ -33,6 +33,10 @@ AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/main/ci/python3.7" if __name__ == '__main__': + sys.path.insert(0, str(Path(__file__).parents[3].absolute() / "dev" / "breeze" / "src")) + from airflow_breeze.branch_defaults import AIRFLOW_BRANCH + + AIRFLOW_CI_IMAGE = f"ghcr.io/{GITHUB_REPOSITORY}/{AIRFLOW_BRANCH}/ci/python3.7" if subprocess.call(args=["docker", "inspect", AIRFLOW_CI_IMAGE], stdout=subprocess.DEVNULL) != 0: print(f'[red]The image {AIRFLOW_CI_IMAGE} is not available.[/]\n') print("\n[yellow]Please run at the earliest convenience:[/]\n\nbreeze build-image --python 3.7\n\n")