From 8430287d1712753340e132fa80a1be5e92d506e9 Mon Sep 17 00:00:00 2001 From: Naga Nandyala Date: Fri, 10 Apr 2026 14:13:13 +1000 Subject: [PATCH 1/3] [Packaging] `az upgrade`: Detect correct cask token for preview vs production During the preview phase (Plan B), the cask is distributed as `azure-cli-preview` via a custom tap, while post-migration it becomes `azure-cli` in homebrew-cask. The `az upgrade` command now checks which cask token is installed and upgrades accordingly. --- src/azure-cli/azure/cli/command_modules/util/custom.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/azure-cli/azure/cli/command_modules/util/custom.py b/src/azure-cli/azure/cli/command_modules/util/custom.py index ca71e1bcaf2..84f9b726f29 100644 --- a/src/azure-cli/azure/cli/command_modules/util/custom.py +++ b/src/azure-cli/azure/cli/command_modules/util/custom.py @@ -132,9 +132,17 @@ def upgrade_version(cmd, update_all=None, yes=None, allow_preview=None): # pyli exit_code = subprocess.call(update_cmd) elif installer == 'HOMEBREW_CASK': logger.debug("Update homebrew cask") + # Determine cask token: 'azure-cli-preview' (custom tap) or 'azure-cli' (homebrew-cask) + cask_token = 'azure-cli' + try: + if subprocess.call(['brew', 'list', '--cask', 'azure-cli-preview'], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: + cask_token = 'azure-cli-preview' + except Exception: # pylint: disable=broad-except + pass exit_code = subprocess.call(['brew', 'update']) if exit_code == 0: - update_cmd = ['brew', 'upgrade', '--cask', 'azure-cli'] + update_cmd = ['brew', 'upgrade', '--cask', cask_token] logger.debug("Update azure cli with '%s'", " ".join(update_cmd)) exit_code = subprocess.call(update_cmd) elif installer == 'PIP': From 8a2754119b3af232ffabb4b1d5fd8012a0f3f436 Mon Sep 17 00:00:00 2001 From: Naga Nandyala Date: Fri, 10 Apr 2026 15:01:06 +1000 Subject: [PATCH 2/3] [Packaging] Fix cask template: remove os stanza, add verified URL, fix completion ordering --- scripts/release/macos/templates/azure-cli.rb.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/release/macos/templates/azure-cli.rb.in b/scripts/release/macos/templates/azure-cli.rb.in index 4b5e7e93385..6941ba1fe62 100644 --- a/scripts/release/macos/templates/azure-cli.rb.in +++ b/scripts/release/macos/templates/azure-cli.rb.in @@ -1,12 +1,12 @@ cask "azure-cli" do arch arm: "arm64", intel: "x86_64" - os macos: "macos" version "{{ version }}" sha256 arm: "{{ arm64_sha }}", intel: "{{ x86_64_sha }}" - url "https://github.com/{{ github_repo }}/releases/download/azure-cli-#{version}/azure-cli-#{version}-#{os}-#{arch}.tar.gz" + url "https://github.com/{{ github_repo }}/releases/download/azure-cli-#{version}/azure-cli-#{version}-macos-#{arch}.tar.gz", + verified: "github.com/{{ github_repo }}/" name "Azure CLI" desc "Microsoft Azure CLI 2.0" homepage "https://docs.microsoft.com/cli/azure/overview" @@ -19,9 +19,9 @@ cask "azure-cli" do depends_on formula: "python@{{ python_version }}" binary "bin/az" - zsh_completion "completions/zsh/_az" bash_completion "completions/bash/az" fish_completion "completions/fish/az.fish" + zsh_completion "completions/zsh/_az" zap trash: "~/.azure" end From 4a2a6f5836d92241218c208790a4e0c29ae0c71e Mon Sep 17 00:00:00 2001 From: Naga Nandyala Date: Fri, 10 Apr 2026 15:13:08 +1000 Subject: [PATCH 3/3] [Packaging] az upgrade: explicit cask detection with early failure and narrower exception handling Address Copilot review feedback: - Check both azure-cli-preview and azure-cli cask tokens explicitly - Fail early with UPGRADE_MSG if neither cask is installed - Catch OSError instead of broad Exception, with debug logging --- .../azure/cli/command_modules/util/custom.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/util/custom.py b/src/azure-cli/azure/cli/command_modules/util/custom.py index 84f9b726f29..c8fdfe427f3 100644 --- a/src/azure-cli/azure/cli/command_modules/util/custom.py +++ b/src/azure-cli/azure/cli/command_modules/util/custom.py @@ -133,13 +133,20 @@ def upgrade_version(cmd, update_all=None, yes=None, allow_preview=None): # pyli elif installer == 'HOMEBREW_CASK': logger.debug("Update homebrew cask") # Determine cask token: 'azure-cli-preview' (custom tap) or 'azure-cli' (homebrew-cask) - cask_token = 'azure-cli' try: - if subprocess.call(['brew', 'list', '--cask', 'azure-cli-preview'], - stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0: + preview_installed = subprocess.call(['brew', 'list', '--cask', 'azure-cli-preview'], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 + cli_installed = subprocess.call(['brew', 'list', '--cask', 'azure-cli'], + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0 + if preview_installed: cask_token = 'azure-cli-preview' - except Exception: # pylint: disable=broad-except - pass + elif cli_installed: + cask_token = 'azure-cli' + else: + raise CLIError(UPGRADE_MSG) + except OSError as ex: + logger.debug("Failed to detect Homebrew cask token: %s", ex) + cask_token = 'azure-cli' exit_code = subprocess.call(['brew', 'update']) if exit_code == 0: update_cmd = ['brew', 'upgrade', '--cask', cask_token]