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
63 changes: 63 additions & 0 deletions .github/scripts/build_agent_setup_bicep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys
from pathlib import Path
from azure.cli.core import get_default_cli
from typing import List, Union


def run_az_command(*args: Union[str, Path]) -> None:
"""Runs an Azure CLI command using the Azure CLI Python SDK."""
cli = get_default_cli()
command = list(args)
exit_code = cli.invoke(command)

if exit_code != 0:
print(f"❌ Failed to execute: {' '.join(command)}")
sys.exit(exit_code)


def get_main_bicep_files(modified_files: List[str]) -> List[Path]:
"""Finds unique folders with modified files and ensures 'main.bicep' exists in each."""
modified_folders = {Path(f).parent for f in modified_files}
return [folder / "main.bicep" for folder in modified_folders if (folder / "main.bicep").exists()]


def build_bicep_file(bicep_file: Path) -> None:
"""Builds a Bicep file using Azure CLI Python SDK and ensures azuredeploy.json is created."""
output_file = bicep_file.with_name("azuredeploy.json")

print(f"🔹 Building Bicep: {bicep_file} -> {output_file}")

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

# Verify if azuredeploy.json was created
if not output_file.exists():
print(f"❌ Build succeeded, but {output_file} was not created!")
sys.exit(1)

print(f"✅ Successfully built: {bicep_file} -> {output_file}")


def main() -> None:
"""Main script execution."""
print("🚀 Running Bicep build using Azure CLI SDK...")

# Get modified Bicep files from pre-commit
modified_files = [Path(f) for f in sys.argv[1:]]

if not modified_files:
print("✅ No modified Bicep files detected. Skipping build.")
sys.exit(0)

# Run Bicep build on each modified file
bicep_files = get_main_bicep_files(modified_files)

for bicep_file in bicep_files:
build_bicep_file(bicep_file)

print("🎉 All Bicep files successfully built!")
sys.exit(0)


if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,14 @@ repos:
entry: python .github/scripts/detect_azure_secrets.py
language: python
types: [file]
- id: bicep-build
name: Regenerate azuredeploy.json for Agent samples
description: "Automatically build Bicep files into azuredeploy.json before commit"
entry: python .github/scripts/build_agent_setup_bicep.py
types: [text]
files: ^scenarios/Agents/setup/.*\.bicep$
language: python
require_serial: true
pass_filenames: true
additional_dependencies:
- azure-cli
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ python-dotenv ~= 1.0
pytest ~= 8.0
pytest-iovis[papermill] == 0.1.0
ipykernel ~= 6.0
azure-cli ~= 2.69
.infra/pytest_plugins/changed_samples
Empty file added scenarios/Agents/README.md
Empty file.
50 changes: 50 additions & 0 deletions scenarios/Agents/media/deploytoazure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions scenarios/Agents/media/visualizebutton.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading