-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/helm pre commit hooks #22
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1446a7c
added helm hooks(first version)
9401f95
changed hook.yaml
4717915
added change in scripts
1c8f823
adding identation test
1ae33b8
adding identation test
ece44ea
changing template rendering hook
d58d19a
changing template rendering hook
f40caf2
rolled back template hook
6a3f59e
new version of template hook
2d2d999
new version of template hook
ca1ecf8
hook update
6f37569
updated template pre-commit hook
6f08062
updated README
2ea6b34
Update README.md
LautaroTorchia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,278 @@ | ||
| # Pre-commit hooks | ||
| # Pre-commit Hooks Collection | ||
|
|
||
| This repo defines Git pre-commit hooks intended for use with [pre-commit](https://pre-commit.com/). The currently | ||
| supported hooks are: | ||
| <div align="center"> | ||
|
|
||
| * **terraform-fmt**: Checks that all Terraform files (`*.tf`) are properly formatted (`terraform fmt --check -diff`). | ||
| * **terraform-validate**: Runs `terraform init -backend=false` and then `terraform validate`. | ||
| > Notes: directories requiring a private registry and lacking credentials are marked as **skipped** (do not fail the commit). Both hooks ignore `.terraform/` and `examples/`. | ||
| **Quality gates for your Infrastructure as Code** | ||
|
|
||
| ## General Usage | ||
| [](LICENSE) | ||
| [](https://pre-commit.com/) | ||
|
|
||
| In each of your repos, add a file called `.pre-commit-config.yaml` with the following contents: | ||
| </div> | ||
|
|
||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| This repository provides a curated collection of **Git pre-commit hooks** designed to enforce best practices and catch issues early in your Infrastructure as Code (IaC) workflows. By integrating these hooks into your development process, you can ensure code quality, consistency, and compliance before changes ever reach your repository. | ||
|
|
||
| ### Why Use Pre-commit Hooks? | ||
|
|
||
| - **Catch issues early** - Identify problems before they reach CI/CD | ||
| - **Fast feedback loop** - Get instant validation on your local machine | ||
| - **Enforce standards** - Maintain consistent code quality across teams | ||
| - **Prevent broken commits** - Block commits that don't meet your criteria | ||
| - **Team collaboration** - Share the same quality gates with everyone | ||
|
|
||
| --- | ||
|
|
||
| ## Available Hooks | ||
|
|
||
| ### Terraform Hooks | ||
|
|
||
| | Hook | Description | What it does | | ||
| |------|-------------|--------------| | ||
| | `terraform-fmt` | **Format checker** | Verifies all `.tf` files are properly formatted using `terraform fmt --check -diff` | | ||
| | `terraform-validate` | **Syntax validator** | Runs `terraform init -backend=false` followed by `terraform validate` to catch configuration errors | | ||
|
|
||
| > **Note:** Directories requiring private registries without credentials are automatically skipped. Both hooks ignore `.terraform/` and `examples/` directories. | ||
|
|
||
| ### Helm Hooks | ||
|
|
||
| | Hook | Description | What it does | | ||
| |------|-------------|--------------| | ||
| | `helm-lint` | **Chart linter** | Validates Helm charts using `helm lint` to check for common issues and best practices | | ||
| | `helm-template-check` | **Template validator** | Renders templates with `helm template` to ensure they generate valid Kubernetes manifests | | ||
|
|
||
| > **Note:** Helm hooks automatically discover charts by locating `Chart.yaml` files in your repository. | ||
|
|
||
|
LautaroTorchia marked this conversation as resolved.
|
||
| --- | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| First, ensure you have [pre-commit](https://pre-commit.com/) installed on your system: | ||
|
|
||
| ```bash | ||
| # macOS | ||
| brew install pre-commit | ||
|
|
||
| # Linux (recommended) | ||
| pipx install pre-commit | ||
|
|
||
| # Linux (alternative) | ||
| pip install --user pre-commit | ||
|
|
||
| # Windows (WSL or Git Bash) | ||
| pip install pre-commit | ||
| ``` | ||
|
|
||
| ### Installation | ||
|
|
||
| ### Step 1: Add the configuration file | ||
|
|
||
| Create a `.pre-commit-config.yaml` file in the root of your repository: | ||
|
|
||
| ```yaml | ||
| repos: | ||
| - repo: git@github.com:craftech-io/pre-commit.git # or https://github.com/craftech-io/pre-commit.git | ||
| rev: <VERSION> | ||
| - repo: git@github.com:craftech-io/pre-commit.git | ||
| # or use: https://github.com/craftech-io/pre-commit.git | ||
| rev: <VERSION> # Use the latest release tag | ||
| hooks: | ||
| # Terraform hooks | ||
| - id: terraform-fmt | ||
| - id: terraform-validate | ||
| verbose: true | ||
| verbose: true # Show detailed output | ||
|
|
||
| # Helm hooks | ||
| - id: helm-lint | ||
| - id: helm-template-check | ||
| ``` | ||
|
|
||
| Next, have every developer: | ||
| > **Tip:** Replace `<VERSION>` with the latest release tag (e.g., `v1.0.0`). Check the [releases page](https://github.com/craftech-io/pre-commit/releases) for available versions. | ||
|
|
||
| **Step 2: Install the hooks** | ||
|
|
||
| 1. Install [pre-commit](https://pre-commit.com/#install). | ||
| - macOS: `brew install pre-commit` | ||
| - Linux: `pipx install pre-commit` (or `pip install --user pre-commit`) | ||
| 2. Run `pre-commit install` in the repo. | ||
| Run this command in your repository: | ||
|
|
||
| ```bash | ||
| pre-commit install | ||
| ``` | ||
|
|
||
| That's it! Now every time you commit a code change (`.tf` file), the hooks in the `hooks:` config will execute. | ||
| If any hook fails, the commit is aborted; if all pass, the commit succeeds. | ||
| **Step 3: You're all set!** | ||
|
|
||
| ## Running Against All Files At Once | ||
| Now, every time you run `git commit`, the configured hooks will automatically execute. If any hook fails, the commit will be blocked, allowing you to fix issues before they're committed. | ||
|
|
||
| ### Example: Formatting and validating all files | ||
| --- | ||
|
|
||
| If you'd like to run the hooks across the whole repo (useful the first time), you can run: | ||
| ## Usage | ||
|
|
||
| ### Automatic Validation (Recommended) | ||
|
|
||
| Once installed, hooks run automatically on every commit: | ||
|
|
||
| ```bash | ||
| # Check formatting for all Terraform files | ||
| pre-commit run terraform-fmt --all-files | ||
| git add . | ||
| git commit -m "feat: add new infrastructure" | ||
| # Hooks will run automatically here! | ||
| ``` | ||
|
|
||
| # Validate all Terraform directories | ||
| pre-commit run terraform-validate --all-files | ||
| ### Manual Execution | ||
|
|
||
| Run hooks manually without committing: | ||
|
|
||
| # Or run every configured hook across the repo | ||
| ```bash | ||
| # Run all configured hooks on staged files | ||
| pre-commit run | ||
|
|
||
| # Run a specific hook on staged files | ||
| pre-commit run terraform-fmt | ||
|
|
||
| # Run hooks on all files in the repository | ||
| pre-commit run --all-files | ||
|
|
||
| # Run a specific hook on all files | ||
| pre-commit run terraform-validate --all-files | ||
| ``` | ||
|
|
||
| ### Common Commands | ||
|
|
||
| ```bash | ||
| # Run all hooks with verbose output | ||
| pre-commit run --all-files -v | ||
|
|
||
| # Run only Terraform hooks | ||
| pre-commit run terraform-fmt --all-files | ||
| pre-commit run terraform-validate --all-files | ||
|
|
||
| # Run only Helm hooks | ||
| pre-commit run helm-lint --all-files | ||
| pre-commit run helm-template-check --all-files | ||
|
|
||
| # Update hooks to the latest version | ||
| pre-commit autoupdate | ||
|
|
||
| # Temporarily bypass hooks (not recommended!) | ||
| git commit --no-verify | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Advanced Configuration | ||
|
|
||
| ### Customizing Hook Behavior | ||
|
|
||
| You can customize hooks in your `.pre-commit-config.yaml`: | ||
|
|
||
| ```yaml | ||
| repos: | ||
| - repo: git@github.com:craftech-io/pre-commit.git | ||
| rev: <VERSION> | ||
| hooks: | ||
| - id: terraform-fmt | ||
| # Run on specific file patterns only | ||
| files: ^modules/ | ||
|
|
||
| - id: terraform-validate | ||
| # Exclude specific directories | ||
| exclude: ^(examples|tests)/ | ||
|
|
||
| - id: helm-lint | ||
| # Always show verbose output | ||
| verbose: true | ||
|
|
||
| - id: helm-template-check | ||
| # Run even if files haven't changed | ||
| always_run: false | ||
| ``` | ||
|
|
||
| ### Combining with Other Hooks | ||
|
|
||
| Mix these hooks with other pre-commit hooks for comprehensive validation: | ||
|
|
||
| ```yaml | ||
| repos: | ||
| # This repository's hooks | ||
| - repo: git@github.com:craftech-io/pre-commit.git | ||
| rev: <VERSION> | ||
| hooks: | ||
| - id: terraform-fmt | ||
| - id: helm-lint | ||
|
|
||
| # Additional hooks from other sources | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v4.5.0 | ||
| hooks: | ||
| - id: trailing-whitespace | ||
| - id: end-of-file-fixer | ||
| - id: check-yaml | ||
| - id: check-added-large-files | ||
| ``` | ||
|
|
||
| > Tip: for detailed output on demand, use `-v`, e.g. `pre-commit run -v terraform-validate --all-files`. | ||
| --- | ||
|
|
||
| ## Contributing | ||
|
|
||
| We welcome contributions! Here's how you can help improve this project: | ||
|
|
||
| ### Adding New Hooks | ||
|
|
||
| 1. **Create the hook script** in the `hooks/` directory | ||
| 2. **Make it executable**: `chmod +x hooks/your-hook.sh` | ||
| 3. **Add entry** to `.pre-commit-hooks.yaml` | ||
| 4. **Test thoroughly** with various scenarios | ||
| 5. **Submit a pull request** with a clear description | ||
|
|
||
| ### Testing Your Changes | ||
|
|
||
| Before submitting a PR, test your hooks: | ||
|
|
||
| ```bash | ||
| # Test on a specific file | ||
| bash hooks/your-hook.sh path/to/test/file | ||
|
|
||
| # Test with pre-commit | ||
| pre-commit try-repo /path/to/your/local/repo your-hook-id --verbose --all-files | ||
| ``` | ||
|
|
||
| ### Development Guidelines | ||
|
|
||
| - Follow existing code style and structure | ||
| - Include error handling and clear error messages | ||
| - Add colorized output for better readability | ||
| - Write descriptive commit messages | ||
| - Update documentation (README, comments) | ||
| - Test on multiple scenarios (success, failure, edge cases) | ||
|
|
||
| ### Reporting Issues | ||
|
|
||
| Found a bug or have a suggestion? Please [open an issue](https://github.com/craftech-io/pre-commit/issues) with: | ||
|
|
||
| - **Clear description** of the problem or enhancement | ||
| - **Steps to reproduce** (for bugs) | ||
| - **Expected vs actual behavior** | ||
| - **Environment details** (OS, tool versions) | ||
|
|
||
| --- | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| - [Pre-commit Documentation](https://pre-commit.com/) | ||
| - [Terraform Documentation](https://www.terraform.io/docs) | ||
| - [Helm Documentation](https://helm.sh/docs/) | ||
| - [Pre-commit Hook Examples](https://github.com/pre-commit/pre-commit-hooks) | ||
|
|
||
| --- | ||
|
|
||
| ## License | ||
|
|
||
| This code is released under the Apache 2.0 License. Please see [LICENSE](LICENSE) for more details. | ||
| This project is released under the **Apache 2.0 License**. | ||
|
|
||
|
|
||
| <div align="center"> | ||
|
|
||
| **[Back to Top](#pre-commit-hooks-collection)** | ||
|
|
||
| Made by Craftech | ||
|
|
||
| </div> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace bold text with proper markdown heading per MD036.
Line 5 uses emphasis (
**...**) for what should be a subtitle/heading. Replace with a proper heading format.📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)
5-5: Emphasis used instead of a heading
(MD036, no-emphasis-as-heading)
🤖 Prompt for AI Agents