From 91eb3f73a857bc091ed8398bfe239106294bfdf6 Mon Sep 17 00:00:00 2001 From: PoAn Yang Date: Thu, 6 Aug 2026 19:50:35 +0900 Subject: [PATCH] [v3-3-test] Fix release dry-run aborting on a workflow run it never dispatched (#71131) (cherry picked from commit de5c8196de5104e60b16eee093ba0141561e69f2) Co-authored-by: PoAn Yang Signed-off-by: PoAn Yang --- .../airflow_breeze/utils/gh_workflow_utils.py | 9 +++++ dev/breeze/tests/test_gh_workflow_utils.py | 40 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 dev/breeze/tests/test_gh_workflow_utils.py diff --git a/dev/breeze/src/airflow_breeze/utils/gh_workflow_utils.py b/dev/breeze/src/airflow_breeze/utils/gh_workflow_utils.py index caaa7b5ac7859..78d19080ea5d1 100644 --- a/dev/breeze/src/airflow_breeze/utils/gh_workflow_utils.py +++ b/dev/breeze/src/airflow_breeze/utils/gh_workflow_utils.py @@ -26,6 +26,7 @@ from airflow_breeze.global_constants import MIN_GH_VERSION from airflow_breeze.utils.console import console_print from airflow_breeze.utils.github import run_gh_command +from airflow_breeze.utils.shared_options import get_dry_run def tigger_workflow(workflow_name: str, repo: str, branch: str = "main", **kwargs): @@ -56,6 +57,11 @@ def tigger_workflow(workflow_name: str, repo: str, branch: str = "main", **kwarg console_print(f"[red]Error running workflow: {result.stderr}[/red]") sys.exit(1) + if get_dry_run(): + # A dry run dispatches nothing, so `gh run list` comes back empty. + console_print(f"[info]Dry run: not looking up or monitoring a run of {workflow_name}.") + return + # Wait for a few seconds to start the workflow run time.sleep(5) @@ -204,6 +210,9 @@ def trigger_workflow_and_monitor( **workflow_fields, ) + if get_dry_run(): + return + workflow_run_id = get_workflow_run_id( workflow_name=workflow_name, repo=repo, diff --git a/dev/breeze/tests/test_gh_workflow_utils.py b/dev/breeze/tests/test_gh_workflow_utils.py new file mode 100644 index 0000000000000..084944a525f28 --- /dev/null +++ b/dev/breeze/tests/test_gh_workflow_utils.py @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from unittest import mock + +from airflow_breeze.utils.gh_workflow_utils import trigger_workflow_and_monitor +from airflow_breeze.utils.shared_options import set_dry_run + + +@mock.patch("airflow_breeze.utils.gh_workflow_utils.monitor_workflow_run") +@mock.patch("airflow_breeze.utils.gh_workflow_utils.make_sure_gh_is_installed") +def test_trigger_workflow_and_monitor_stops_after_the_dispatch_in_dry_run(_, mock_monitor): + """A dry run dispatches nothing, so the empty `gh run list` must not read as a missing run.""" + set_dry_run(True) + try: + trigger_workflow_and_monitor( + workflow_name="release-constraints.yml", + repo="apache/airflow", + version="3.2.0rc1", + ref="v3-2-stable", + ) + finally: + set_dry_run(False) + + mock_monitor.assert_not_called()