This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch fork-ci-test-merge-commit in repository https://gitbox.apache.org/repos/asf/airflow.git
commit f8da851e7cc3fffba3760f5ec1833748ffbf45b5 Author: Jarek Potiuk <[email protected]> AuthorDate: Mon Nov 16 02:18:24 2026 +0900 Reproduce a fork CI failure on the merge it tested The local reproduction steps checked out the pushed commit, while the fork run tested it merged with the base branch, so a failure caused by the merged changes would not reproduce. Generated-by: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01NyQq9U7i5HhjDgrQ9qd3gq --- .../src/airflow_breeze/utils/reproduce_ci.py | 29 ++++++++++++++++++++ dev/breeze/tests/test_reproduce_ci.py | 32 +++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/dev/breeze/src/airflow_breeze/utils/reproduce_ci.py b/dev/breeze/src/airflow_breeze/utils/reproduce_ci.py index 87dd17f484b..3edc5b55aa0 100644 --- a/dev/breeze/src/airflow_breeze/utils/reproduce_ci.py +++ b/dev/breeze/src/airflow_breeze/utils/reproduce_ci.py @@ -20,6 +20,7 @@ from __future__ import annotations import os import shlex +import subprocess from dataclasses import dataclass import click @@ -134,9 +135,37 @@ def build_reproduction_command_from_context( return ReproductionCommand(argv=argv, comment=comment) +def read_head_parents() -> list[str]: + """The parents of the checked-out commit; empty when git cannot tell.""" + result = subprocess.run( + ["git", "rev-list", "--parents", "-n", "1", "HEAD"], capture_output=True, text=True, check=False + ) + return result.stdout.split()[1:] if result.returncode == 0 else [] + + def build_checkout_reproduction_commands(github_repository: str) -> list[ReproductionCommand]: """Build git commands needed to reproduce the current CI checkout locally.""" current_commit_sha = os.environ.get("GITHUB_SHA") or os.environ.get("COMMIT_SHA") or commit_sha() + # A fork CI run tests the pushed commit merged with a base branch commit (merge-with-base action); + # the merge commit is made in the job and never pushed, so it is made again locally. + parents = read_head_parents() if os.environ.get("GITHUB_SHA") else [] + if len(parents) == 2 and parents[1] == current_commit_sha: + base_sha = parents[0] + return [ + ReproductionCommand( + argv=["git", "fetch", f"https://github.com/{github_repository}.git", current_commit_sha], + comment="Fetch the pushed commit", + ), + ReproductionCommand( + argv=["git", "fetch", f"https://github.com/{APACHE_AIRFLOW_GITHUB_REPOSITORY}.git", base_sha], + comment="Fetch the base branch commit fork CI merged it with", + ), + ReproductionCommand(argv=["git", "checkout", current_commit_sha]), + ReproductionCommand( + argv=["git", "merge", "--no-edit", base_sha], + comment="Merge them as fork CI did", + ), + ] github_ref = os.environ.get("GITHUB_REF", "") github_ref_parts = github_ref.split("/") if len(github_ref_parts) == 4 and github_ref_parts[:2] == ["refs", "pull"]: diff --git a/dev/breeze/tests/test_reproduce_ci.py b/dev/breeze/tests/test_reproduce_ci.py index dd6490d3ae4..d17819f27ee 100644 --- a/dev/breeze/tests/test_reproduce_ci.py +++ b/dev/breeze/tests/test_reproduce_ci.py @@ -106,7 +106,8 @@ def test_build_checkout_reproduction_commands_fetches_pull_request_ref(pr_ref_ki assert commands[1].argv == ["git", "checkout", "merge-sha"] -def test_build_checkout_reproduction_commands_plain_sha(monkeypatch): [email protected]("airflow_breeze.utils.reproduce_ci.read_head_parents", autospec=True, return_value=["abc123"]) +def test_build_checkout_reproduction_commands_plain_sha(mock_parents, monkeypatch): monkeypatch.delenv("GITHUB_REF", raising=False) monkeypatch.setenv("GITHUB_SHA", "def456") @@ -116,6 +117,35 @@ def test_build_checkout_reproduction_commands_plain_sha(monkeypatch): assert commands[0].argv == ["git", "checkout", "def456"] [email protected]( + ("parents", "merged"), + [ + pytest.param(["base789", "def456"], True, id="fork-ci-merge"), + pytest.param(["def456", "other"], False, id="other-merge"), + pytest.param([], False, id="parents-unknown"), + ], +) [email protected]("airflow_breeze.utils.reproduce_ci.read_head_parents", autospec=True) +def test_build_checkout_reproduction_commands_recreates_the_fork_ci_merge( + mock_parents, parents, merged, monkeypatch +): + mock_parents.return_value = parents + monkeypatch.setenv("GITHUB_REF", "refs/heads/my-change") + monkeypatch.setenv("GITHUB_SHA", "def456") + + commands = build_checkout_reproduction_commands("someone/airflow") + + if merged: + assert [command.argv for command in commands] == [ + ["git", "fetch", "https://github.com/someone/airflow.git", "def456"], + ["git", "fetch", "https://github.com/apache/airflow.git", "base789"], + ["git", "checkout", "def456"], + ["git", "merge", "--no-edit", "base789"], + ] + else: + assert [command.argv for command in commands] == [["git", "checkout", "def456"]] + + @mock.patch("airflow_breeze.utils.reproduce_ci.get_console", autospec=True) def test_print_local_reproduction_renders_copyable_commands(mock_get_console, monkeypatch): monkeypatch.setenv("CI", "true")
