7171)
7272from airflow_breeze .utils .console import console_print , get_console
7373from airflow_breeze .utils .exclude_from_matrix import excluded_combos
74+ from airflow_breeze .utils .fork_compare import get_upstream_file
7475from airflow_breeze .utils .functools_cache import clearable_cache
7576from airflow_breeze .utils .kubernetes_utils import get_kubernetes_python_combos
7677from airflow_breeze .utils .packages import get_available_distributions , get_suspended_provider_ids
@@ -901,6 +902,7 @@ class SelectiveChecks:
901902 "_github_event" ,
902903 "_fork_push" ,
903904 "_fork_changes_truncated" ,
905+ "_fork_merge_base" ,
904906 }
905907
906908 def __init__ (
@@ -918,11 +920,14 @@ def __init__(
918920 selective_tests_on_push : bool = False ,
919921 fork_push : bool = False ,
920922 fork_changes_truncated : bool = False ,
923+ fork_merge_base : str | None = None ,
921924 ):
922925 """
923926 :param fork_push: the push happened in a contributor fork (AIP-120); ``files`` are the
924927 changes against apache/airflow and the run is selected like a pull request.
925928 :param fork_changes_truncated: the compare API capped the changed files of a fork push.
929+ :param fork_merge_base: the apache/airflow commit a fork push is compared with; previous
930+ versions of changed files are read there instead of from the pushed commit's parent.
926931 """
927932 self ._files = files
928933 # A changed test helper selects the tests that import it, as if those test files had changed;
@@ -952,6 +957,7 @@ def __init__(
952957 self ._selective_tests_on_push = selective_tests_on_push
953958 self ._fork_push = fork_push
954959 self ._fork_changes_truncated = fork_changes_truncated
960+ self ._fork_merge_base = fork_merge_base
955961 self ._new_toml : dict [str , Any ] = {}
956962 self ._old_toml : dict [str , Any ] = {}
957963
@@ -1012,6 +1018,18 @@ def _get_full_run_events(self) -> list[GithubEvents]:
10121018 return [GithubEvents .SCHEDULE , GithubEvents .WORKFLOW_DISPATCH ]
10131019 return [GithubEvents .PUSH , GithubEvents .SCHEDULE , GithubEvents .WORKFLOW_DISPATCH ]
10141020
1021+ def _get_previous_file_content (self , path : str ) -> str | None :
1022+ if self ._fork_merge_base :
1023+ return get_upstream_file (path = path , ref = self ._fork_merge_base )
1024+ result = run_command (
1025+ ["git" , "show" , f"{ self ._commit_ref } ^:{ path } " ],
1026+ capture_output = True ,
1027+ text = True ,
1028+ cwd = AIRFLOW_ROOT_PATH ,
1029+ check = False ,
1030+ )
1031+ return result .stdout if result .returncode == 0 else None
1032+
10151033 def _is_pull_request_like (self ) -> bool :
10161034 return self ._github_event == GithubEvents .PULL_REQUEST or self ._fork_push
10171035
@@ -1289,6 +1307,13 @@ def run_ui_e2e_tests(self) -> bool:
12891307 f"'{ FULL_TESTS_NEEDED_LABEL } ' label is set[/]"
12901308 )
12911309 return True
1310+ # The UI files of a truncated fork change set may be among the files the compare API
1311+ # did not list, so the file match below cannot rule them out.
1312+ if self ._fork_changes_truncated :
1313+ console_print (
1314+ f"[warning]{ FileGroupForCi .UI_FILES } e2e enabled because the fork change set is truncated[/]"
1315+ )
1316+ return True
12921317 matched_files = self ._matching_files (FileGroupForCi .UI_FILES , CI_FILE_GROUP_MATCHES )
12931318 if matched_files :
12941319 console_print (
@@ -1871,21 +1896,14 @@ def pyproject_toml_changed(self) -> bool:
18711896 f"Could not get pyproject.toml from { self ._commit_ref } [/]"
18721897 )
18731898 return False
1874- old_result = run_command (
1875- ["git" , "show" , f"{ self ._commit_ref } ^:pyproject.toml" ],
1876- capture_output = True ,
1877- text = True ,
1878- cwd = AIRFLOW_ROOT_PATH ,
1879- check = False ,
1880- )
1881- if old_result .returncode != 0 :
1899+ old_content = self ._get_previous_file_content ("pyproject.toml" )
1900+ if old_content is None :
18821901 console_print (
1883- f"[warning]Cannot determine pyproject.toml changes. "
1884- f"Could not get pyproject.toml from { self ._commit_ref } ^[/]"
1902+ "[warning]Cannot determine pyproject.toml changes. Could not get its previous version[/]"
18851903 )
18861904 return False
18871905 self ._new_toml = tomllib .loads (new_result .stdout )
1888- self ._old_toml = tomllib .loads (old_result . stdout )
1906+ self ._old_toml = tomllib .loads (old_content )
18891907 return True
18901908
18911909 @cached_property
@@ -2357,20 +2375,13 @@ def provider_dependency_bump(self) -> bool:
23572375 if new_result .returncode != 0 :
23582376 continue
23592377
2360- # Get the old version of the file
2361- old_result = run_command (
2362- ["git" , "show" , f"{ self ._commit_ref } ^:{ pyproject_file } " ],
2363- capture_output = True ,
2364- text = True ,
2365- cwd = AIRFLOW_ROOT_PATH ,
2366- check = False ,
2367- )
2368- if old_result .returncode != 0 :
2378+ old_content = self ._get_previous_file_content (pyproject_file )
2379+ if old_content is None :
23692380 continue
23702381
23712382 try :
23722383 new_toml = tomllib .loads (new_result .stdout )
2373- old_toml = tomllib .loads (old_result . stdout )
2384+ old_toml = tomllib .loads (old_content )
23742385 except Exception :
23752386 continue
23762387
0 commit comments