Skip to content

Commit c65354c

Browse files
authored
ci,fix: Pin version of bicep-cli used by pre-commit (#219)
Bicep includes its version and a hash of the template as metadata in the file produced when running `bicep build`. Different versions of bicep-cli produce differing values for those fields, which can break `pre-commit run --all` when run against changes that don't touch any bicep files. Pinning bicep-cli should keep those fields consistent until bicep is intentionally upgraded.
1 parent e4a621b commit c65354c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

.github/scripts/build_agent_setup_bicep.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23
from pathlib import Path
34
from azure.cli.core import get_default_cli
@@ -26,6 +27,10 @@ def build_bicep_file(bicep_file: Path) -> None:
2627
output_file = bicep_file.with_name("azuredeploy.json")
2728

2829
print(f"🔹 Building Bicep: {bicep_file} -> {output_file}")
30+
os.environ.update({"AZURE_BICEP_USE_BINARY_FROM_PATH": "false", "AZURE_BICEP_CHECK_VERSION": "false"})
31+
32+
# Pin the bicep CLI to minimize pre-commit failures due to modified metadata in files.
33+
run_az_command("bicep", "install", "--version", "v0.33.93")
2934

3035
# Run az bicep build using Azure CLI SDK
3136
run_az_command("bicep", "build", "--file", str(bicep_file), "--outfile", str(output_file))

.pre-commit-config.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ repos:
4343
- id: bicep-build
4444
name: Regenerate azuredeploy.json for Agent samples
4545
description: "Automatically build Bicep files into azuredeploy.json before commit"
46-
entry: python .github/scripts/build_agent_setup_bicep.py
4746
types: [text]
4847
files: ^scenarios/Agents/setup/.*\.bicep$
49-
language: python
5048
require_serial: true
5149
pass_filenames: true
52-
additional_dependencies:
53-
- azure-cli
50+
entry: python
51+
language: system
52+
args: ["-m", "tox", "-qqq", "run", "-e", "build-agent-bicep", "--"]

tox.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ commands = typos {posargs}
2828
deps =
2929
-r dev-requirements.txt
3030
commands = pytest {posargs}
31+
32+
33+
[testenv:build-agent-bicep]
34+
deps =
35+
azure-cli
36+
set_env =
37+
AZURE_CONFIG_DIR={env_tmp_dir}/azure
38+
commands = python .github/scripts/build_agent_setup_bicep.py {posargs}

0 commit comments

Comments
 (0)