diff --git a/.github/workflows/build_arm.yml b/.github/workflows/build_arm.yml new file mode 100644 index 00000000..f3cb290a --- /dev/null +++ b/.github/workflows/build_arm.yml @@ -0,0 +1,31 @@ +name: Bicep -> ARM + +on: + push: + branches: [main] + paths: + # only run if bicep files changed + - 'Environments/**/*.bicep' + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - uses: actions/checkout@v3 + + - name: Install Bicep + run: az bicep install && az bicep upgrade + + - name: Build Bicep -> ARM + run: python ./tools/build-arm.py + + - name: Commit changes + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + git commit -am "Rebuild ARM templates" + git push diff --git a/.gitignore b/.gitignore index b6e47617..e35851f0 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,14 @@ dmypy.json # Pyre type checker .pyre/ + +.DS_Store + +[lL]ocal +.[lL]ocal + +.venv +.env + +local.settings.json +local.parameters.json \ No newline at end of file diff --git a/Environments/README.md b/Environments/README.md index 6052a48e..ae20f97d 100644 --- a/Environments/README.md +++ b/Environments/README.md @@ -10,9 +10,9 @@ The sample Catalog consists of a few catalog items (ARM Template + associated ma ## ARM and Bicep -Each catalog item has _main.bicep_ file in addition to the ARM template (_azuredeploy.json_). This is because the ARM templates in this repository are written in [bicep](https://github.com/Azure/bicep) and transpiled to ARM using the [build-arm.py](/tools/build-arm.py) script in the [tools](/tools/) folder. The script simply walks the Environments folder and runs the [`az bicep build`](https://learn.microsoft.com/en-us/cli/azure/bicep?view=azure-cli-latest#az-bicep-build) command on each folder's main.bicep file. +Each catalog item has _main.bicep_ file in addition to the ARM template (_azuredeploy.json_). This is because the ARM templates in this repository are written in [bicep](https://github.com/Azure/bicep) and transpiled to ARM using the [build-arm.py](/tools/build-arm.py) script in the [tools](/tools/) folder. The script simply walks the Environments folder and runs the [`az bicep build`](https://learn.microsoft.com/en-us/cli/azure/bicep?view=azure-cli-latest#az-bicep-build) command on each folder's main.bicep file, and is automatically run via the [build_arm.yml](/.github/workflows/build_arm.yml) workflow any time a bicep file changes. -**Please note: This is not a requirement for creating catalog item templates. It is done in this repo to make it easier to understand what is being deployed in each templates.** +**Please note: This is not a requirement for creating catalog item templates. It is done in this repo to make it easier to understand what is being deployed in each template.** ### What is Bicep? diff --git a/tools/build-arm.py b/tools/build-arm.py index 25031d5c..0507a2ad 100644 --- a/tools/build-arm.py +++ b/tools/build-arm.py @@ -6,6 +6,7 @@ import os import shutil import subprocess + from pathlib import Path repository_root = Path(__file__).resolve().parent.parent @@ -21,6 +22,17 @@ environments.append(Path(dirpath)) # image_names.append(Path(dirpath).name) +# get the full path to the git executable +git = shutil.which('git') + +for environment in environments: + print(f' Ensuring: {environment}/azuredeploy.json') + if not (environment / 'azuredeploy.json').exists(): + # if the azuredeploy.json file doesn't exist, create it + (environment / 'azuredeploy.json').touch() + # run the git command to add the azuredeploy.json file + subprocess.run([git, 'add', environment / 'azuredeploy.json']) + # get the full path to the azure cli executable az = shutil.which('az')