Skip to content

Commit

Permalink
feat: add pre-commit hook (#221)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Moss <2951486+adam-moss@users.noreply.github.com>
  • Loading branch information
adam-moss authored Aug 4, 2023
1 parent 52e8d5d commit f2ddc4e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
- id: regal-lint
stages:
- pre-commit
language: golang
name: policy file linting
description: policy file linting with Regal from Styra built from source
entry: regal lint
files: (\.rego)$

- id: regal-lint-use-path
stages:
- pre-commit
language: system
name: policy file linting
description: policy file linting with Regal from Styra using system $PATH
entry: regal lint
files: (\.rego)$
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,40 @@ Note that at this point in time, Regal only considers the line following the ign
entire blocks of code (like rules, functions or even packages). See [configuration](#configuration) if you want to
ignore certain rules altogether.

## Using Regal with Pre-Commit

[Pre-Commit](https://pre-commit.com) is a framework for managing and maintaining multi-language pre-commit hooks.

To use Regal with pre-commit, add this to your `.pre-commit-config.yaml`

```yaml
- repo: https://github.com/StyraInc/regal
rev: v0.5.0 # Use the ref you want to point at
hooks:
- id: regal-lint
# - id: ...
```

### Hooks Available

#### `regal-lint`

![commit-msg hook](https://img.shields.io/badge/hook-pre--commit-informational?logo=git)

Runs Regal against all staged `.rego` files, aborting the commit if any fail.

- requires the `go` build chain is installed and available on `$PATH`
- will build and install the tagged version of Regal in an isolated `GOPATH`
- ensures compatibility between versions

#### `regal-lint-use-path`

![commit-msg hook](https://img.shields.io/badge/hook-pre--commit-informational?logo=git)

Runs Regal against all staged `.rego` files, aborting the commit if any fail.

- requires the `regal` package is already installed and available on `$PATH`.

## Resources

### Documentation
Expand Down

0 comments on commit f2ddc4e

Please sign in to comment.