diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bc2f44220..24a6a6cae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,9 +4,22 @@ repos: hooks: - id: black language_version: python3 - + - repo: https://github.com/pycqa/flake8 rev: 7.0.0 hooks: - - id: flake8 - args: [--extend-ignore=E501] \ No newline at end of file + - id: flake8 + args: [--extend-ignore=E501] + + - repo: local + hooks: + - id: bicep + name: bicep + description: Lint and build Bicep files + entry: ./scripts/generate_arm_templates.sh + language: script + files: \.bicep$ + require_serial: true + args: # Bicep files that we want to generate ARM templates from + - -f=./infra/deployment.bicep + - -f=./extensions/infrastructure/main.bicep diff --git a/scripts/generate_arm_templates.sh b/scripts/generate_arm_templates.sh new file mode 100755 index 000000000..a9208105f --- /dev/null +++ b/scripts/generate_arm_templates.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -e + +az bicep version 2>/dev/null || az bicep install + +TEMPLATES=() + +for ARG in $@; do + # If the argument is supplied with "-f", then it is a template file that needs to be built + if [[ $ARG == -f=* ]]; then + TEMPLATES+=(${ARG#-f=}) + else + # Otherwise, it is a file that has been edited + az bicep format -f $ARG + git add $ARG + fi +done + +# Build the templates +for TEMPLATE in ${TEMPLATES[@]}; do + az bicep build -f $TEMPLATE + git add "${TEMPLATE%.bicep}.json" # Change the extension from .bicep to .json +done