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

Finish refactoring of breeze-dependent pre-commits to use breeze shell #35830

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,8 @@ repos:
files: ^docs/.*\.py$
exclude: ^docs/rtd-deprecation
require_serial: true
additional_dependencies: ['rich>=12.4.4', 'inputimeout', 'pyyaml', 'jsonschema', 'filelock', 'markdown-it-py']
- id: check-provider-yaml-valid
additional_dependencies: ['rich>=12.4.4']
- id: check-provider-yaml-valid
name: Validate provider.yaml files
entry: ./scripts/ci/pre_commit/pre_commit_check_provider_yaml_files.py
language: python
Expand All @@ -1064,7 +1064,7 @@ repos:
entry: ./scripts/ci/pre_commit/pre_commit_migration_reference.py
pass_filenames: false
files: ^airflow/migrations/versions/.*\.py$|^docs/apache-airflow/migrations-ref\.rst$
additional_dependencies: ['rich>=12.4.4', 'inputimeout', 'pyyaml', 'jsonschema', 'filelock', 'markdown-it-py']
additional_dependencies: ['rich>=12.4.4']
- id: update-er-diagram
name: Update ER diagram
language: python
Expand Down
24 changes: 0 additions & 24 deletions dev/breeze/src/airflow_breeze/utils/run_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

from rich.markup import escape

from airflow_breeze.branch_defaults import AIRFLOW_BRANCH
from airflow_breeze.global_constants import APACHE_AIRFLOW_GITHUB_REPOSITORY
from airflow_breeze.utils.ci_group import ci_group
from airflow_breeze.utils.console import Output, get_console
from airflow_breeze.utils.path_utils import (
Expand Down Expand Up @@ -382,28 +380,6 @@ def check_if_image_exists(image: str) -> bool:
return cmd_result.returncode == 0


def get_ci_image_for_pre_commits() -> str:
Copy link
Member Author

Choose a reason for hiding this comment

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

Not needed any more after this last PR from the series .

github_repository = os.environ.get("GITHUB_REPOSITORY", APACHE_AIRFLOW_GITHUB_REPOSITORY)
python_version = "3.8"
airflow_image = f"ghcr.io/{github_repository}/{AIRFLOW_BRANCH}/ci/python{python_version}"
skip_image_pre_commits = os.environ.get("SKIP_IMAGE_PRE_COMMITS", "false")
if skip_image_pre_commits[0].lower() == "t":
get_console().print(
f"[info]Skipping image check as SKIP_IMAGE_PRE_COMMITS is set to {skip_image_pre_commits}[/]"
)
sys.exit(0)
if not check_if_image_exists(
image=airflow_image,
):
get_console().print(f"[red]The image {airflow_image} is not available.[/]\n")
get_console().print(
f"\n[yellow]Please run this to fix it:[/]\n\n"
f"breeze ci-image build --python {python_version}\n\n"
)
sys.exit(1)
return airflow_image


def _run_compile_internally(command_to_execute: list[str], dev: bool) -> RunCommandResult:
from filelock import SoftFileLock, Timeout

Expand Down
53 changes: 12 additions & 41 deletions scripts/ci/pre_commit/pre_commit_migration_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,21 @@
# under the License.
from __future__ import annotations

import os
import sys
from pathlib import Path

if __name__ not in ("__main__", "__mp_main__"):
raise SystemExit(
"This file is intended to be executed as an executable program. You cannot use it as a module."
f"To run this script, run the ./{__file__} command"
)

AIRFLOW_SOURCES = Path(__file__).parents[3].resolve()
GITHUB_REPOSITORY = os.environ.get("GITHUB_REPOSITORY", "apache/airflow")
os.environ["SKIP_GROUP_OUTPUT"] = "true"
sys.path.insert(0, str(Path(__file__).parent.resolve()))
from common_precommit_utils import console, initialize_breeze_precommit, run_command_via_breeze_shell

if __name__ == "__main__":
sys.path.insert(0, str(AIRFLOW_SOURCES / "dev" / "breeze" / "src"))
from airflow_breeze.global_constants import DEFAULT_PYTHON_MAJOR_MINOR_VERSION, MOUNT_SELECTED
from airflow_breeze.params.shell_params import ShellParams
from airflow_breeze.utils.console import get_console
from airflow_breeze.utils.docker_command_utils import get_extra_docker_flags
from airflow_breeze.utils.run_utils import get_ci_image_for_pre_commits, run_command
initialize_breeze_precommit(__name__, __file__)

shell_params = ShellParams(python=DEFAULT_PYTHON_MAJOR_MINOR_VERSION, db_reset=True, backend="none")
airflow_image = get_ci_image_for_pre_commits()
cmd_result = run_command(
[
"docker",
"run",
"-t",
*get_extra_docker_flags(mount_sources=MOUNT_SELECTED),
"-e",
"SKIP_ENVIRONMENT_INITIALIZATION=true",
"--pull",
"never",
airflow_image,
"-c",
"python3 /opt/airflow/scripts/in_container/run_migration_reference.py",
],
check=False,
env=shell_params.env_variables_for_docker_commands,
cmd_result = run_command_via_breeze_shell(
["python3", "/opt/airflow/scripts/in_container/run_migration_reference.py"],
backend="sqlite",
)
if cmd_result.returncode != 0:
console.print(
"[warning]\nIf you see strange stacktraces above, "
"run `breeze ci-image build --python 3.8` and try again."
)
if cmd_result.returncode != 0:
get_console().print(
"[warning]If you see strange stacktraces above, "
"run `breeze ci-image build --python 3.8` and try again."
)
sys.exit(cmd_result.returncode)
sys.exit(cmd_result.returncode)
8 changes: 8 additions & 0 deletions scripts/in_container/run_migration_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from typing import TYPE_CHECKING, Iterable

from alembic.script import ScriptDirectory
from rich.console import Console
from tabulate import tabulate

from airflow import __version__ as airflow_version
Expand All @@ -36,6 +37,8 @@
if TYPE_CHECKING:
from alembic.script import Script

console = Console(width=400, color_system="standard")

airflow_version = re.match(r"(\d+\.\d+\.\d+).*", airflow_version).group(1) # type: ignore
project_root = Path(__file__).parents[2].resolve()

Expand Down Expand Up @@ -180,9 +183,14 @@ def ensure_filenames_are_sorted(revisions):


if __name__ == "__main__":
console.print("[bright_blue]Updating migration reference")
revisions = list(reversed(list(get_revisions())))
console.print("[bright_blue]Making sure airflow version updated")
ensure_airflow_version(revisions=revisions)
revisions = list(reversed(list(get_revisions())))
console.print("[bright_blue]Making sure filenames are sorted")
ensure_filenames_are_sorted(revisions=revisions)
revisions = list(get_revisions())
console.print("[bright_blue]Updating documentation")
update_docs(revisions=revisions)
console.print("[green]Migrations OK")