Skip to content

Commit

Permalink
feat(pre-commit-hook): Update documentation and tag (#530)
Browse files Browse the repository at this point in the history
* feat(pre-commit-hook): Update documentation and tag
  • Loading branch information
dannyvassallo authored Jul 9, 2024
1 parent 57d712c commit 7697069
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ name: Pre-Commit Hook CI
on:
push:
paths:
- 'pre_commit_hooks/**'
- 'pre_commit_hooks_tests/**'
- '.github/workflows/pre-commit.yml'
- pre_commit_hooks/**
- pre_commit_hooks_tests/**
- .github/workflows/pre-commit.yml
- .pre-commit-config.yaml
- .pre-commit-hooks.yaml
pull_request:
paths:
- 'pre_commit_hooks/**'
- 'pre_commit_hooks_tests/**'
- '.github/workflows/pre-commit.yml'
- pre_commit_hooks/**
- pre_commit_hooks_tests/**
- .github/workflows/pre-commit.yml
- .pre-commit-config.yaml
- .pre-commit-hooks.yaml
jobs:
run-unit-tests-and-lint:
runs-on: ubuntu-latest
Expand Down
13 changes: 6 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# TODO: Update this to use the release from CFN once merged
repos:
- repo: https://github.com/dannyvassallo/cloudformation-guard
rev: pre-commit-v0.0.97
- repo: https://github.com/aws-cloudformation/cloudformation-guard
rev: pre-commit-v0.0.1
hooks:
- id: cfn-guard
args:
- "--operation=validate"
- "--rules=guard/resources/validate/rules-dir/"
- --operation=validate
- --rules=guard/resources/validate/rules-dir/
files: ^guard/resources/validate/data-dir/.*
- id: cfn-guard
args:
- "--operation=test"
- "--dir=pre_commit_hooks_tests/resources/"
- --operation=test
- --dir=pre_commit_hooks_tests/resources/
files: ^pre_commit_hooks_tests/resources.*
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Take this [survey](https://amazonmr.au1.qualtrics.com/jfe/form/SV_bpyzpfoYGGuuUl
* [AWS Rule Registry](#registry)
* [Use Guard as a Docker Image](#docker)
* [Use Guard as a CI tool](#ci)
* [Use Guard as a pre-commit hook](#pre-commit-hook)
* [Contribute using the DevContainer in VSCode](#devcontainer)
* [License](#license)

Expand Down Expand Up @@ -630,6 +631,31 @@ Guard is great for CI checks with the Junit output format, making the process of
[Get the template here!](https://github.com/aws-cloudformation/cloudformation-guard/tree/main/guard-examples/ci/.circleci/config.yml)
## <a name="pre-commit-hook"></a> Use Guard as a pre-commit hook
Guard is available as a pre-commit hook and offers both the `test` and `validate` operations. You can use them by adding a variation of the following configuration to your `.pre-commit-config.yaml` file:
```yaml
repos:
- repo: https://github.com/aws-cloudformation/cloudformation-guard
rev: pre-commit-v0.0.1
hooks:
# Validate
- id: cfn-guard
args:
- --operation=validate # Specify the validate operation
- --rules=path/to/rules/ # Rules directory
files: ^path/to/data/.* # Directory to watch for changes and validate against
# Test
- id: cfn-guard
args:
- --operation=test # Specify the test operation
- --dir=path/to/resources/ # Directory that contains rules & their tests
files: ^path/to/resources.* # Same directory supplied to the --dir arg so that rule and test file changes trigger a run
```
**NOTE**: The args for the pre-commit hook are not identical to the flags you would pass directly to Guard. In the case of this hook, you cannot pass a `data` flag to `validate` as it depends on the `filenames` from the hook and you can only use the `dir` flag for the `test` hook.
## <a name="devcontainer"></a> Contribute using the DevContainer in VSCode
### Setup
Expand Down

0 comments on commit 7697069

Please sign in to comment.