Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pre-commit-hook): Update documentation and tag #530

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.*
24 changes: 24 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,29 @@ 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
```

## <a name="devcontainer"></a> Contribute using the DevContainer in VSCode

### Setup
Expand Down
Loading