This is an automated email from the ASF dual-hosted git repository.
amoghdesai pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 7a28183ebbd Fix remote reference in execution API version prek hook
(#63973)
7a28183ebbd is described below
commit 7a28183ebbdf0a594920076b63cbad2b1333191a
Author: Amogh Desai <[email protected]>
AuthorDate: Fri Mar 20 17:04:58 2026 +0530
Fix remote reference in execution API version prek hook (#63973)
---
scripts/ci/prek/check_execution_api_versions.py | 27 +++++++++++++----------
scripts/ci/prek/common_prek_utils.py | 29 +++++++++++++++++++++++++
2 files changed, 44 insertions(+), 12 deletions(-)
diff --git a/scripts/ci/prek/check_execution_api_versions.py
b/scripts/ci/prek/check_execution_api_versions.py
index 652fc16cb2a..872812b7ec9 100755
--- a/scripts/ci/prek/check_execution_api_versions.py
+++ b/scripts/ci/prek/check_execution_api_versions.py
@@ -30,7 +30,7 @@ import sys
import tempfile
from pathlib import Path
-from common_prek_utils import console
+from common_prek_utils import console, get_remote_for_main
DATAMODELS_PREFIX =
"airflow-core/src/airflow/api_fastapi/execution_api/datamodels/"
VERSIONS_PREFIX =
"airflow-core/src/airflow/api_fastapi/execution_api/versions/"
@@ -39,19 +39,20 @@ TARGET_BRANCH = "main"
def get_changed_files_ci() -> list[str]:
"""Get changed files in CI by comparing against main."""
+ remote = get_remote_for_main()
+ ref = f"{remote}/{TARGET_BRANCH}"
+
fetch_result = subprocess.run(
- ["git", "fetch", "upstream", TARGET_BRANCH],
+ ["git", "fetch", remote, TARGET_BRANCH],
capture_output=True,
text=True,
check=False,
)
if fetch_result.returncode != 0:
- console.print(
- f"[yellow]WARNING: Failed to fetch origin/{TARGET_BRANCH}:
{fetch_result.stderr.strip()}[/]"
- )
+ console.print(f"[yellow]WARNING: Failed to fetch {ref}:
{fetch_result.stderr.strip()}[/]")
is_main = not os.environ.get("GITHUB_BASE_REF")
- diff_target = "HEAD~1" if is_main else f"origin/{TARGET_BRANCH}...HEAD"
+ diff_target = "HEAD~1" if is_main else f"{ref}...HEAD"
result = subprocess.run(
["git", "diff", "--name-only", diff_target],
@@ -61,18 +62,18 @@ def get_changed_files_ci() -> list[str]:
)
if result.returncode != 0:
console.print(
- f"[yellow]WARNING: git diff against origin/{TARGET_BRANCH} failed
(exit {result.returncode}), "
+ f"[yellow]WARNING: git diff against {ref} failed (exit
{result.returncode}), "
"retrying with deeper fetch...[/]"
)
subprocess.run(
- ["git", "fetch", "--deepen=50", "origin", TARGET_BRANCH],
+ ["git", "fetch", "--deepen=50", remote, TARGET_BRANCH],
capture_output=True,
text=True,
check=False,
)
try:
result = subprocess.run(
- ["git", "diff", "--name-only",
f"origin/{TARGET_BRANCH}...HEAD"],
+ ["git", "diff", "--name-only", f"{ref}...HEAD"],
capture_output=True,
text=True,
check=True,
@@ -115,9 +116,10 @@ def generate_schema(cwd: Path) -> dict:
def generate_schema_from_main() -> dict:
"""Generate schema from main branch using worktree."""
+ remote = get_remote_for_main()
+ ref = f"{remote}/{TARGET_BRANCH}"
worktree_path = Path(tempfile.mkdtemp()) / "airflow-main"
- ref = f"origin/{TARGET_BRANCH}"
- subprocess.run(["git", "fetch", "origin", TARGET_BRANCH],
capture_output=True, check=False)
+ subprocess.run(["git", "fetch", remote, TARGET_BRANCH],
capture_output=True, check=False)
subprocess.run(["git", "worktree", "add", str(worktree_path), ref],
capture_output=True, check=True)
try:
return generate_schema(worktree_path)
@@ -191,8 +193,9 @@ def main() -> int:
for f in datamodel_files:
console.print(f" - [magenta]{f}[/]")
console.print("")
+ remote = get_remote_for_main()
console.print(
- f"Schema diff against [cyan]origin/{TARGET_BRANCH}[/] detected
differences.\n"
+ f"Schema diff against [cyan]{remote}/{TARGET_BRANCH}[/]
detected differences.\n"
"\n"
"Please add or update a version file under:\n"
f" [cyan]{VERSIONS_PREFIX}[/]\n"
diff --git a/scripts/ci/prek/common_prek_utils.py
b/scripts/ci/prek/common_prek_utils.py
index 4bfb9b09ac2..95d9fb61afc 100644
--- a/scripts/ci/prek/common_prek_utils.py
+++ b/scripts/ci/prek/common_prek_utils.py
@@ -451,6 +451,35 @@ def get_imports_from_file(file_path: Path, *,
only_top_level: bool) -> list[str]
return imports
+def get_remote_for_main() -> str:
+ """
+ Return the remote name to use when fetching main.
+ Prefers the remote that points to apache/airflow; otherwise uses origin.
+ """
+ result = subprocess.run(
+ ["git", "remote", "-v"],
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+ if result.returncode != 0:
+ return "origin"
+
+ apache_remote = None
+ origin_remote = None
+ for line in result.stdout.splitlines():
+ parts = line.split()
+ if len(parts) >= 2:
+ name, url = parts[0], parts[1]
+ if "apache/airflow" in url:
+ apache_remote = name
+ break
+ if name == "origin":
+ origin_remote = name
+
+ return apache_remote or origin_remote or "origin"
+
+
def retrieve_gh_token(*, token: str | None = None, description: str, scopes:
str) -> str:
if token:
return token