Skip to content

Commit

Permalink
Add pre-commit for Bicep files
Browse files Browse the repository at this point in the history
  • Loading branch information
cecheta committed Feb 5, 2024
1 parent 93f9edd commit 00a5288
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
19 changes: 16 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
- 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
24 changes: 24 additions & 0 deletions scripts/generate_arm_templates.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 00a5288

Please sign in to comment.