Skip to content

Commit 3d95202

Browse files
authored
[ARM] Fix #32098: az bicep install: Fix a bug where the installation was skipped when --version was specified unless bicep.use_binary_from_path was explicitly set to false (#32337)
1 parent bc15429 commit 3d95202

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/azure-cli/azure/cli/command_modules/resource/_bicep.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,17 @@ def run_bicep_command(cli_ctx, args, auto_install=True, custom_env=None):
115115

116116

117117
def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, stdout=True):
118-
if _use_binary_from_path(cli_ctx):
118+
if _use_binary_from_path(cli_ctx) and release_tag is None:
119+
# Only use the Bicep executable from PATH when no specific version is requested.
119120
from shutil import which
120121

121122
if which("bicep") is None:
122123
raise ValidationError(
123124
'Could not find the "bicep" executable on PATH. To install Bicep via Azure CLI, set the "bicep.use_binary_from_path" configuration to False and run "az bicep install".' # pylint: disable=line-too-long
124125
)
125126

127+
_logger.debug("Using Bicep CLI from PATH.")
128+
126129
return
127130

128131
system = platform.system()
@@ -131,11 +134,13 @@ def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, s
131134

132135
if os.path.isfile(installation_path):
133136
if not release_tag:
137+
print(f"Bicep CLI is already installed at '{installation_path}'. Skipping installation as no specific version was requested.") # pylint: disable=line-too-long
134138
return
135139

136140
installed_version = _get_bicep_installed_version(installation_path)
137141
target_version = _extract_version(release_tag)
138142
if installed_version and target_version and installed_version == target_version:
143+
print(f"Bicep CLI {installed_version} is already installed at '{installation_path}'.")
139144
return
140145

141146
installation_dir = os.path.dirname(installation_path)

src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_use_bicep_cli_from_path_false_after_install(
8484
response.read.return_value = b"test"
8585
urlopen_stub.return_value = response
8686

87-
user_binary_from_path_stub.return_value = False
87+
user_binary_from_path_stub.return_value = True
8888
get_use_binary_from_path_config_stub.return_value = "if_found_in_ci"
8989

9090
# Act
@@ -206,13 +206,13 @@ def test_ensure_bicep_installation_skip_download_if_installed_version_matches_re
206206
@mock.patch("azure.cli.command_modules.resource._bicep.get_use_binary_from_path_config")
207207
@mock.patch("azure.cli.command_modules.resource._bicep._get_bicep_installation_path")
208208
@mock.patch("shutil.which")
209-
def test_ensure_bicep_installation_skip_download_if_use_binary_from_path_is_true(
209+
def test_ensure_bicep_installation_skip_download_if_use_binary_from_path_is_true_and_no_version_is_specified(
210210
self, which_stub, _get_bicep_installation_path_mock, get_use_binary_from_path_config_stub
211211
):
212212
which_stub.return_value = True
213213
get_use_binary_from_path_config_stub.return_value = "true"
214214

215-
ensure_bicep_installation(self.cli_ctx, release_tag="v0.1.0")
215+
ensure_bicep_installation(self.cli_ctx, release_tag=None)
216216

217217
_get_bicep_installation_path_mock.assert_not_called()
218218

0 commit comments

Comments
 (0)