Skip to content
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
1 change: 1 addition & 0 deletions airflow-core/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ repos:
name: Update migration ref doc
language: python
entry: ../scripts/ci/prek/migration_reference.py
args: ["--app", "airflow"]
pass_filenames: false
files:
(?x)
Expand Down
1 change: 1 addition & 0 deletions providers/edge3/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ repos:
name: Update migration ref doc for Edge3
language: python
entry: ../../scripts/ci/prek/migration_reference.py
args: ["--app", "edge3"]
pass_filenames: false
files: >
(?x)
Expand Down
1 change: 1 addition & 0 deletions providers/fab/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ repos:
name: Update migration ref doc for FAB
language: python
entry: ../../scripts/ci/prek/migration_reference.py
args: ["--app", "fab"]
pass_filenames: false
files: >
(?x)
Expand Down
4 changes: 3 additions & 1 deletion scripts/ci/prek/migration_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# ///
from __future__ import annotations

import sys

from common_prek_utils import (
initialize_breeze_prek,
run_command_via_breeze_run,
Expand All @@ -32,7 +34,7 @@
initialize_breeze_prek(__name__, __file__)

cmd_result = run_command_via_breeze_run(
["python3", "/opt/airflow/scripts/in_container/run_migration_reference.py"],
["python3", "/opt/airflow/scripts/in_container/run_migration_reference.py", *sys.argv[1:]],
backend="sqlite",
)

Expand Down
19 changes: 16 additions & 3 deletions scripts/in_container/run_migration_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from __future__ import annotations

import argparse
import os
import re
import textwrap
Expand Down Expand Up @@ -53,7 +54,9 @@ def replace_text_between(file: Path, start: str, end: str, replacement_text: str
original_text = file.read_text()
leading_text = original_text.split(start)[0]
trailing_text = original_text.split(end)[1]
file.write_text(leading_text + start + replacement_text + end + trailing_text)
new_text = leading_text + start + replacement_text + end + trailing_text
if new_text != original_text:
file.write_text(new_text)


def wrap_backticks(val):
Expand Down Expand Up @@ -275,11 +278,21 @@ def correct_mismatching_revision_nums(revisions: Iterable[Script]):
if revises_id_match is None:
raise RuntimeError(f"Revises: not found in {file}")
new_content = new_content.replace(revises_id_match.group(1), down_revision_match.group(1), 1)
file.write_text(new_content)
if new_content != content:
file.write_text(new_content)


if __name__ == "__main__":
apps = ["airflow", "fab", "edge3"]
all_apps = ["airflow", "fab", "edge3"]
parser = argparse.ArgumentParser(description="Update migration references and docs.")
parser.add_argument(
"--app",
choices=all_apps,
default=None,
help="Only process this app (default: all apps).",
)
args = parser.parse_args()
apps = [args.app] if args.app else all_apps
for app in apps:
console.print(f"[bright_blue]Updating migration reference for {app}")
revisions = list(reversed(list(get_revisions(app))))
Expand Down
Loading