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
22 changes: 17 additions & 5 deletions dev/breeze/doc/images/output-commands.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_run.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54d7d635ab887d0f556a9cebcab7f63f
d4841617ec2b8d96643f6695adcb68d6
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_shell.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
95bba676df9c9dccc5b0798fbc269f6e
a35521c64446afe2657126bec1132254
2 changes: 1 addition & 1 deletion dev/breeze/doc/images/output_start-airflow.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a76fae2707fcab0cc46a68f1186c6a08
ed465431e2702e05546a60b46dd16908
14 changes: 3 additions & 11 deletions dev/breeze/src/airflow_breeze/commands/ci_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
fix_ownership_using_docker,
perform_environment_checks,
)
from airflow_breeze.utils.github import retrieve_github_token
from airflow_breeze.utils.path_utils import AIRFLOW_HOME_PATH, AIRFLOW_ROOT_PATH
from airflow_breeze.utils.run_utils import run_command

Expand Down Expand Up @@ -776,16 +777,7 @@ def upgrade(

console_print("[info]Running upgrade of important CI environment.[/]")

# Resolve GitHub token: prefer --github-token / GITHUB_TOKEN env var, fall back to gh CLI
if not github_token:
gh_token_result = run_command(
["gh", "auth", "token"],
capture_output=True,
text=True,
check=False,
)
if gh_token_result.returncode == 0 and gh_token_result.stdout.strip():
github_token = gh_token_result.stdout.strip()
github_token = retrieve_github_token(github_token)

# Create a copy of the environment to pass to commands
command_env = os.environ.copy()
Expand All @@ -795,7 +787,7 @@ def upgrade(
console_print("[success]GitHub token set in environment.[/]")
else:
console_print(
"[warning]Could not retrieve GitHub token from --github-token or gh CLI. "
"[warning]Could not retrieve GitHub token from --github-token, gh CLI, or token env. "
"Commands may fail if they require authentication.[/]"
)

Expand Down
15 changes: 2 additions & 13 deletions dev/breeze/src/airflow_breeze/commands/issues_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from airflow_breeze.utils.click_utils import BreezeGroup
from airflow_breeze.utils.confirm import Answer, user_confirm
from airflow_breeze.utils.console import console_print
from airflow_breeze.utils.run_utils import run_command
from airflow_breeze.utils.github import retrieve_github_token
from airflow_breeze.utils.shared_options import get_dry_run


Expand All @@ -42,18 +42,7 @@ def issues_group():

def _resolve_github_token(github_token: str | None) -> str | None:
"""Resolve GitHub token from option, environment, or gh CLI."""
if github_token:
return github_token
gh_token_result = run_command(
["gh", "auth", "token"],
capture_output=True,
text=True,
check=False,
dry_run_override=False,
)
if gh_token_result.returncode == 0:
return gh_token_result.stdout.strip()
return None
return retrieve_github_token(github_token)


def _get_collaborator_logins(repo) -> set[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
fix_ownership_using_docker,
perform_environment_checks,
)
from airflow_breeze.utils.github import retrieve_github_token
from airflow_breeze.utils.helm_chart_utils import chart_version
from airflow_breeze.utils.packages import (
PackageSuspendedException,
Expand Down Expand Up @@ -2666,16 +2667,7 @@ class ProviderPRInfo(NamedTuple):
all_prs.update(prs)
provider_prs[provider_id] = filtered_prs
all_retrieved_prs.update(provider_prs[provider_id])
if not github_token:
# Get GitHub token from gh CLI and set it in environment copy
gh_token_result = run_command(
["gh", "auth", "token"],
capture_output=True,
text=True,
check=False,
)
if gh_token_result.returncode == 0:
github_token = gh_token_result.stdout.strip()
github_token = retrieve_github_token(github_token)
g = Github(github_token)
repo = g.get_repo("apache/airflow")
pull_requests: dict[int, PullRequest.PullRequest | Issue.Issue] = {}
Expand Down Expand Up @@ -4164,6 +4156,7 @@ def generate_issue_content(
excluded_prs = []
prs = [pr for pr in change_prs if pr is not None and pr not in excluded_prs]

github_token = retrieve_github_token(github_token) or ""
g = Github(github_token)
repo = g.get_repo("apache/airflow")
pull_requests: dict[int, PullRequestOrIssue] = {}
Expand Down
14 changes: 4 additions & 10 deletions dev/breeze/src/airflow_breeze/commands/workflow_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from airflow_breeze.utils.console import console_print
from airflow_breeze.utils.custom_param_types import BetterChoice
from airflow_breeze.utils.gh_workflow_utils import trigger_workflow_and_monitor
from airflow_breeze.utils.run_utils import run_command
from airflow_breeze.utils.github import run_gh_command

WORKFLOW_NAME_MAPS = {
"publish-docs": "publish-docs-to-s3.yml",
Expand Down Expand Up @@ -127,24 +127,18 @@ def workflow_run_publish(
)
sys.exit(1)
if os.environ.get("GITHUB_TOKEN", ""):
console_print("\n[warning]Your authentication will use GITHUB_TOKEN environment variable.")
console_print(
"\nThis might not be what you want unless your token has "
"sufficient permissions to trigger workflows."
)
console_print(
"If you remove GITHUB_TOKEN, workflow_run will use the authentication you already "
"set-up with `gh auth login`.\n"
"\n[warning]GITHUB_TOKEN is set; Breeze will try your `gh auth login` first and only "
"use this token as a fallback. The fallback token must have workflow-trigger scope."
)
console_print(
f"[blue]Validating ref: {ref}[/blue]",
)

if not skip_tag_validation:
tag_result = run_command(
tag_result = run_gh_command(
["gh", "api", f"repos/apache/airflow/git/refs/tags/{ref}"],
capture_output=True,
check=False,
)

stdout = tag_result.stdout.decode("utf-8")
Expand Down
8 changes: 4 additions & 4 deletions dev/breeze/src/airflow_breeze/utils/gh_workflow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from airflow_breeze.global_constants import MIN_GH_VERSION
from airflow_breeze.utils.console import console_print
from airflow_breeze.utils.run_utils import run_command
from airflow_breeze.utils.github import run_gh_command


def tigger_workflow(workflow_name: str, repo: str, branch: str = "main", **kwargs):
Expand All @@ -50,7 +50,7 @@ def tigger_workflow(workflow_name: str, repo: str, branch: str = "main", **kwarg
command.extend(["-f", f"{key}={value}"])

console_print(f"[blue]Running command: {' '.join(command)}[/blue]")
result = run_command(command, capture_output=True, check=False)
result = run_gh_command(command, capture_output=True)

if result.returncode != 0:
console_print(f"[red]Error running workflow: {result.stderr}[/red]")
Expand Down Expand Up @@ -109,7 +109,7 @@ def get_workflow_run_id(workflow_name: str, repo: str) -> int:
"databaseId",
]

result = run_command(command, capture_output=True, check=False)
result = run_gh_command(command, capture_output=True)
if result.returncode != 0:
console_print(f"[red]Error fetching workflow run ID: {result.stderr}[/red]")
sys.exit(1)
Expand Down Expand Up @@ -139,7 +139,7 @@ def get_workflow_run_info(run_id: str, repo: str, fields: str) -> dict:
make_sure_gh_is_installed()
command = ["gh", "run", "view", run_id, "--json", fields, "--repo", repo]

result = run_command(command, capture_output=True, check=False)
result = run_gh_command(command, capture_output=True)
if result.returncode != 0:
console_print(f"[red]Error fetching workflow run status: {result.stderr}[/red]")
sys.exit(1)
Expand Down
Loading
Loading