Skip to content

Commit 6b3a838

Browse files
Scenario/agents (#205)
* Build bicep git hooks * Build bicep git hooks * Revert run sample * Fix Pytest command * Revert * Switch to python * Switch to python * Switch to python * Switch to python * Switch to python * Remove shell script * Reconcile all commits * Fix wait script * Fix wait script * Fix depends on * Fix AI kind * Fix overlapping roles * Fix A Recordset * Fix syntax * Check existing storage * More cleanups * Fix pre-commit
1 parent 015cdbf commit 6b3a838

File tree

58 files changed

+9807
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+9807
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import sys
2+
from pathlib import Path
3+
from azure.cli.core import get_default_cli
4+
from typing import List, Union
5+
6+
7+
def run_az_command(*args: Union[str, Path]) -> None:
8+
"""Runs an Azure CLI command using the Azure CLI Python SDK."""
9+
cli = get_default_cli()
10+
command = list(args)
11+
exit_code = cli.invoke(command)
12+
13+
if exit_code != 0:
14+
print(f"❌ Failed to execute: {' '.join(command)}")
15+
sys.exit(exit_code)
16+
17+
18+
def get_main_bicep_files(modified_files: List[str]) -> List[Path]:
19+
"""Finds unique folders with modified files and ensures 'main.bicep' exists in each."""
20+
modified_folders = {Path(f).parent for f in modified_files}
21+
return [folder / "main.bicep" for folder in modified_folders if (folder / "main.bicep").exists()]
22+
23+
24+
def build_bicep_file(bicep_file: Path) -> None:
25+
"""Builds a Bicep file using Azure CLI Python SDK and ensures azuredeploy.json is created."""
26+
output_file = bicep_file.with_name("azuredeploy.json")
27+
28+
print(f"🔹 Building Bicep: {bicep_file} -> {output_file}")
29+
30+
# Run az bicep build using Azure CLI SDK
31+
run_az_command("bicep", "build", "--file", str(bicep_file), "--outfile", str(output_file))
32+
33+
# Verify if azuredeploy.json was created
34+
if not output_file.exists():
35+
print(f"❌ Build succeeded, but {output_file} was not created!")
36+
sys.exit(1)
37+
38+
print(f"✅ Successfully built: {bicep_file} -> {output_file}")
39+
40+
41+
def main() -> None:
42+
"""Main script execution."""
43+
print("🚀 Running Bicep build using Azure CLI SDK...")
44+
45+
# Get modified Bicep files from pre-commit
46+
modified_files = [Path(f) for f in sys.argv[1:]]
47+
48+
if not modified_files:
49+
print("✅ No modified Bicep files detected. Skipping build.")
50+
sys.exit(0)
51+
52+
# Run Bicep build on each modified file
53+
bicep_files = get_main_bicep_files(modified_files)
54+
55+
for bicep_file in bicep_files:
56+
build_bicep_file(bicep_file)
57+
58+
print("🎉 All Bicep files successfully built!")
59+
sys.exit(0)
60+
61+
62+
if __name__ == "__main__":
63+
main()

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,14 @@ repos:
4040
entry: python .github/scripts/detect_azure_secrets.py
4141
language: python
4242
types: [file]
43+
- id: bicep-build
44+
name: Regenerate azuredeploy.json for Agent samples
45+
description: "Automatically build Bicep files into azuredeploy.json before commit"
46+
entry: python .github/scripts/build_agent_setup_bicep.py
47+
types: [text]
48+
files: ^scenarios/Agents/setup/.*\.bicep$
49+
language: python
50+
require_serial: true
51+
pass_filenames: true
52+
additional_dependencies:
53+
- azure-cli

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ python-dotenv ~= 1.0
44
pytest ~= 8.0
55
pytest-iovis[papermill] == 0.1.0
66
ipykernel ~= 6.0
7+
azure-cli ~= 2.69
78
.infra/pytest_plugins/changed_samples

scenarios/Agents/README.md

Whitespace-only changes.
Lines changed: 50 additions & 0 deletions
Loading
Lines changed: 53 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)