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
9 changes: 9 additions & 0 deletions dev/breeze/src/airflow_breeze/utils/gh_workflow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions dev/breeze/tests/test_gh_workflow_utils.py
Original file line number Diff line number Diff line change
@@ -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()
Loading