Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 34 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- main

jobs:
test:
unit:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
Expand All @@ -18,5 +18,36 @@ jobs:
- name: Install taskfile
run: sudo snap install task --classic

- name: Run tests
run: task test
- name: Run unit tests
run: task test:unit

pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v6
with:
fetch-depth: 0
fetch-tags: true

- name: Install taskfile
run: sudo snap install task --classic

- name: Install GoReleaser
run: sudo snap install --classic goreleaser

- name: Install pre-commit dependencies
run: |
sudo snap install helm --classic
sudo npm install -g bats
sudo npm install -g https://github.com/ztombol/bats-assert
sudo npm install -g https://github.com/ztombol/bats-support
pip install pre-commit

- name: Install the plugin
run: |
task build:plugin -- --snapshot
task reinstall

- name: Run pre-commit hook tests
run: task test:pre-commit
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,15 @@ Build the binaries and plugin will require providing the `--snapshot` flag if yo
task build:plugin -- --snapshot
```

bats install

```
brew install bats-core
brew tap kaos/shell
brew install bats-assert
```


### New release

Bump the changelog:
Expand Down
8 changes: 4 additions & 4 deletions cmd/helm-values/internal/precommit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const preCommitConfigPath = ".pre-commit-config.yaml"
var schemaPreCommitHook = &PreCommitHook{
ID: "helm-values-schema",
Name: "Generate Helm values schema",
Entry: "helm values schema . --git-add",
Entry: "helm values schema --git-add .",
Language: "system",
Files: "^.*/values\\.yaml$",
Files: "values\\.yaml$",
PassFilenames: lo.ToPtr(false),
}
var docsPreCommitHook = &PreCommitHook{
ID: "helm-values-docs",
Name: "Generate Helm values documentation",
Entry: "helm values docs . --git-add",
Entry: "helm values docs --git-add .",
Language: "system",
Files: "^.*/values\\.yaml$",
Files: "values\\.yaml$",
PassFilenames: lo.ToPtr(false),
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/helm-values/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func CommandModeline(logger *logrus.Logger, group *cobra.Group) *cobra.Command {
cfg := config.NewModelineConfig()

cmd := &cobra.Command{
Use: "modeline [flags] chart_ref [values_file]",
Use: "modeline [flags] chart_ref values_file",
Short: "Add yaml-language-server modeline to values file",
GroupID: group.ID,
Args: cobra.RangeArgs(1, 2),
Expand Down
20 changes: 19 additions & 1 deletion taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# yaml-language-server: $schema=https://taskfile.dev/schema.json

version: '3'

tasks:
run:
cmds:
- go run ./cmd/helm-values {{.CLI_ARGS}}

build:bin:
desc: Build production binary
cmds:
Expand All @@ -20,14 +26,26 @@ tasks:
desc: Reinstall the plugin locally
cmds:
- helm plugin uninstall values || true
- helm plugin install ./dist/values-*.tgz
- helm plugin install ./dist/values-$(git describe --tags --abbrev=0).tgz

test:
desc: Run all tests
cmds:
- task: test:unit
- task: test:pre-commit

test:unit:
desc: Run unit tests
cmds:
- go test ./pkg/...
- go test ./cmd/...

test:pre-commit:
desc: Run pre-commit hook tests
dir: ./tests/pre-commit
cmds:
- bats ./tests.bats

clean:
desc: Clean build artifacts
cmds:
Expand Down
32 changes: 32 additions & 0 deletions tests/pre-commit/tests.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bats

setup() {
if command -v brew &> /dev/null; then
BREW_PREFIX="$(brew --prefix)"
load "${BREW_PREFIX}/lib/bats-support/load.bash"
load "${BREW_PREFIX}/lib/bats-assert/load.bash"
else
NPM_PREFIX="$(npm config get prefix)"
load "${NPM_PREFIX}/lib/node_modules/bats-support/load.bash"
load "${NPM_PREFIX}/lib/node_modules/bats-assert/load.bash"
fi

touch values.yaml
task run -- pre-commit
}

teardown() {
rm -f values.yaml
rm -f .pre-commit-config.yaml
}

@test "Generate helm values schema" {
pre-commit run --files values.yaml
pre-commit run --files values.yaml | grep 'Generate Helm values schema' | grep 'Passed'
assert_success
}

@test "Generate helm values documentation" {
pre-commit run --files values.yaml | grep 'Generate Helm values documentation' | grep Passed
assert_success
}