Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Azure4DevOps/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.
https://github.com/Azure4DevOps/check-azure-bicep

azure azure-devops bicep cli git github-actions pre-commit shift-left

Last synced: 2 months ago
JSON representation

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.

Awesome Lists containing this project

README

        

[![Build Status](https://dev.azure.com/Azure4DevOps/Azure4DevOps/_apis/build/status/Azure4DevOps.check-azure-bicep-ci?branchName=master)](https://dev.azure.com/Azure4DevOps/Azure4DevOps/_build/latest?definitionId=2&branchName=master)
[![CI](https://github.com/Azure4DevOps/check-azure-bicep/actions/workflows/github-action-ci.yml/badge.svg)](https://github.com/Azure4DevOps/check-azure-bicep/actions/workflows/github-action-ci.yml)
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/Azure4DevOps/check-azure-bicep)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/Azure4DevOps/check-azure-bicep?include_prereleases)
[![pre-commit][pre-commit-image]][pre-commit-link]

[pre-commit-image]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&style=flat-square
[pre-commit-link]: https://github.com/pre-commit/pre-commit

# check-azure-bicep

[pre-commit](https://pre-commit.com/) hooks for [Azure Bicep](https://github.com/Azure/bicep) validation,
with built-in support for GitHub Workflows, Azure Pipelines, and more! Enabling [shift left](https://devopedia.org/shift-left) approach for [Azure Bicep](https://github.com/Azure/bicep) infrastructure as code.

## About

This repository provide one hook to use with [pre-commit](https://pre-commit.com/) that validate bicep files: it will call `az bicep build`.

It requires the `az bicep` toolchain installed, and uses [`az bicep`](https://github.com/Azure/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`

![alt text](https://raw.githubusercontent.com/Azure4DevOps/check-azure-bicep.example/master/example.gif)

### Azure Bicep Install

To install `az bicep` use [install](https://docs.microsoft.com/pl-pl/azure/azure-resource-manager/bicep/install) or [install](https://github.com/Azure/bicep) 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:

```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.

```yaml
- 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`

```yaml
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`

```yaml
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](https://opensource.org/licenses/MIT) license.