Skip to content

Commit 4e821b2

Browse files
committed
Closes #1249
1 parent e130513 commit 4e821b2

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

.pre-commit-hooks.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,13 @@
3737
require_serial: false
3838
minimum_pre_commit_version: "2.9.0"
3939
stages: [pre-commit, pre-merge-commit, pre-push, manual]
40+
41+
- id: conftest-doc
42+
name: Conftest Doc Policy Documentation
43+
description: Generate policy documentation, fails if docs are out of date. Requires args with policy directory path.
44+
entry: conftest doc
45+
language: golang
46+
pass_filenames: false
47+
require_serial: true
48+
minimum_pre_commit_version: "2.9.0"
49+
stages: [pre-commit, pre-merge-commit, pre-push, manual]

docs/pre_commit.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ repos:
2121
The `conftest-test` hook validates your configuration files against policies,
2222
while the `conftest-verify` hook runs unit tests for your policies.
2323

24+
## Documentation Check
25+
26+
The `conftest-doc` hook ensures your policy documentation stays in sync with
27+
your Rego policies. It runs `conftest doc` and if the generated documentation
28+
differs from what's committed, pre-commit will fail. The updated documentation
29+
files are written, so you can simply stage them and re-commit.
30+
31+
**Important:** You must specify the policy directory via `args` - this hook
32+
requires at least one directory path argument.
33+
34+
```yaml
35+
repos:
36+
- repo: https://github.com/open-policy-agent/conftest
37+
rev: v0.64.0
38+
hooks:
39+
- id: conftest-doc
40+
args: [path/to/your/policies] # Required: policy directory to document
41+
# To specify an output directory, use -o:
42+
# args: [-o, docs/, path/to/your/policies]
43+
```
44+
45+
## Additional Hooks
46+
2447
Additional hooks are available including `conftest-pull` for downloading
2548
policies and `conftest-fmt` for formatting Rego files. See the
2649
[.pre-commit-hooks.yaml](https://github.com/open-policy-agent/conftest/blob/main/.pre-commit-hooks.yaml)

0 commit comments

Comments
 (0)