check-azure-bicep
check-azure-bicep copied to clipboard
Pre-commit hooks for Azure Bicep validation, with built-in support for GitHub Workflows, Azure Pipelines, and more! Enabling shift left approach for Azure Bicep infrastructure as code.
check-azure-bicep
pre-commit hooks for Azure Bicep validation, with built-in support for GitHub Workflows, Azure Pipelines, and more! Enabling shift left approach for Azure Bicep infrastructure as code.
About
This repository provide one hook to use with pre-commit that validate bicep files: it will call az bicep build.
It requires the az bicep toolchain installed, and uses az bicep under the hood.
Demo
Example usage of pre-commit run --all-files and
git commit after hook innstall in git repository pre-commit install

Azure Bicep Install
To install az bicep use install or install or az bicep install for Azure cli.
pre-commit Install
Before you can run hooks, you need to have the pre-commit package manager installed. Using pip:
# install using pip
pip install pre-commit
# check if working - expected print with version like `pre-commit 3.2.2`
pre-commit --version
# setup the git repo for hooks
pre-commit install
# periodically run updates to your pre-commit config to make sure you always have the latest version of the hooks
pre-commit autoupdate
Example usage
Add a snippet to your .pre-commit-config.yaml file in root of repository.
- repo: https://github.com/Azure4DevOps/check-azure-bicep
rev: v0.2.1 # ${LATEST_SHA_OR_VERSION}
hooks:
- id: check-azure-bicep
Example local run
run pre-commit install to set up the git hook scripts in your git repository # scan all modyfied miles before making commint (git hooks)
or
run pre-commit run --all-files # scanning all files
at result all bicep files will or modified will be validated doing az bicep build
Example Azure Pipelines usage azure-pipelines-ci.yml
pool:
vmImage: "ubuntu-latest"
steps:
- script: |
pip install pre-commit
pre-commit --version
pre-commit run --all-files
displayName: Execute pre-commit
Example Github Workflow usage github-action-ci.yml
build:
runs-on: ubuntu-latest
steps:
- name: Execute pre-commit
run: |
pip install pre-commit
pre-commit --version
pre-commit run --all-files
📄 License
This project is distributed under the terms of the MIT license.