Skip to content

Commit

Permalink
Merge pull request #15 from losisin/add-pre-coomit-hook-and-update-do…
Browse files Browse the repository at this point in the history
…cumentation

add pre-commit hook, update docs and bump version
  • Loading branch information
losisin committed Nov 10, 2023
2 parents 3aaf10b + 391191c commit 9509d2f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/losisin/helm-values-schema-json
rev: v0.1.6
hooks:
- id: helm-schema
args:
# Single or multiple yamlFiles as inputs (comma-separated)
- --input=values.yaml
# Output file path (default "values.schema.json")
- --output=values.schema.json
# Draft version (4, 6, 7, 2019, or 2020) (default 2020)
- --draft=2020
7 changes: 7 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- id: helm-schema
args: []
description: Helm plugin for generating values.schema.json from single or multiple values files. Works only with Helm3 charts.
entry: scripts/git-hook.sh
language: script
name: Helm Docs
require_serial: true
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,67 @@ Installed plugin: schema
- Save output with custom name and location - default is values.schema.json in current working directory
- Change schema draft version - default is draft 2020-12

## Integrations

There are several ways to automate schema generation with this plugin. Main reason is that the json schema file can be hard to follow and we as humans tend to forget and update routine tasks. So why not automate it?

### GitHub actions

There is GitHub action that I've build using typescript and published on marketplace. You can find it [here](https://github.com/marketplace/actions/helm-values-schema-json-action). Basic usage is as follows:

```yaml
name: Generate values schema json
on:
- pull_request
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Generate values schema json
uses: losisin/helm-values-schema-json-action@v1
with:
input: values.yaml
```

### pre-commit hook

With pre-commit, you can ensure your JSON schema is kept up-to-date each time you make a commit.

First [install pre-commit](https://pre-commit.com/#install) and then create or update a `.pre-commit-config.yaml` in the root of your Git repo with at least the following content:

```yaml
repos:
- repo: https://github.com/losisin/helm-values-schema-json
rev: v0.1.6
hooks:
- id: helm-schema
args: ["-input", "values.yaml"]
```

Then run:

```bash
pre-commit install
pre-commit install-hooks
```

Further changes to your chart files will cause an update to json schema when you make a commit.

### Husky

This is a great tool for adding git hooks to your project. You can find it's documentation [here](https://typicode.github.io/husky/). Here is how you can use it:

```json
"husky": {
"hooks": {
"pre-commit": "helm schema -input values.yaml"
}
},
```

## Usage

```bash
Expand Down
6 changes: 3 additions & 3 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: "schema"
version: "0.1.5"
version: "0.1.6"
usage: "generate values.schema.json from values yaml"
description: "Helm plugin for generating values.schema.json from multiple values files."
ignoreFlags: false
command: "$HELM_PLUGIN_DIR/schema"
hooks:
install: "cd $HELM_PLUGIN_DIR; ./install-binary.sh"
update: "cd $HELM_PLUGIN_DIR; HELM_PLUGIN_UPDATE=1 ./install-binary.sh"
install: "cd $HELM_PLUGIN_DIR; ./scripts/install.sh"
update: "cd $HELM_PLUGIN_DIR; HELM_PLUGIN_UPDATE=1 ./scripts/install.sh"
9 changes: 9 additions & 0 deletions scripts/git-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env sh

set -e

if ! 'helm plugin list | grep -q "schema"' > /dev/null 2>&1; then
echo "Please install helm-values-schema-json plugin! https://github.com/losisin/helm-values-schema-json#install"
fi

helm schema "${@}"
File renamed without changes.

0 comments on commit 9509d2f

Please sign in to comment.