Skip to content

Commit 49ba5d2

Browse files
committed
feat: add helm docs and schema gen
Add Helm docs and Helm JSON Schema generation. Signed-off-by: Mateusz Urbanek <mateusz.urbanek@siderolabs.com>
1 parent f189649 commit 49ba5d2

File tree

7 files changed

+176
-5
lines changed

7 files changed

+176
-5
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2026-01-16T08:46:36Z by kres 6f7b97a-dirty.
3+
# Generated on 2026-01-27T14:17:50Z by kres f189649-dirty.
44

55
# common variables
66

@@ -171,6 +171,9 @@ local-%: ## Builds the specified target defined in the Dockerfile using the loc
171171
fi; \
172172
done'
173173

174+
check-dirty:
175+
@if test -n "`git status --porcelain`"; then echo "Source tree is dirty"; git status; git diff; exit 1 ; fi
176+
174177
generate: ## Generate .proto definitions.
175178
@$(MAKE) local-$@ DEST=./
176179

internal/config/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ const (
7878
// HelmUnitTestVersion is the version of helm unit test plugin.
7979
// renovate: datasource=github-tags depName=helm-unittest/helm-unittest
8080
HelmUnitTestVersion = "v1.0.3"
81+
// HelmValuesSchemaJSONVersion is the version of helm values-schema-json plugin.
82+
// renovate: datasource=github-tags depName=losisin/helm-values-schema-json
83+
HelmValuesSchemaJSONVersion = "v2.3.1"
84+
// HelmDocsVersion is the version of helm-docs tool.
85+
// renovate: datasource=github-tags depName=norwoodj/helm-docs
86+
HelmDocsVersion = "v1.14.2"
8187
// LoginActionVersion is the version of login github action.
8288
// renovate: datasource=github-tags depName=docker/login-action
8389
LoginActionVersion = "v3.6.0"

internal/project/auto/git.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ func (builder *builder) DetectGit() (bool, error) {
106106

107107
// BuildGit builds steps for Git repository.
108108
func (builder *builder) BuildGit() error {
109-
builder.commonInputs = append(builder.commonInputs, common.NewRepository(builder.meta))
109+
builder.commonInputs = append(
110+
builder.commonInputs,
111+
common.NewRepository(builder.meta),
112+
common.NewCheckDirty(builder.meta),
113+
)
110114

111115
return nil
112116
}

internal/project/auto/golang.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/siderolabs/kres/internal/dag"
1919
"github.com/siderolabs/kres/internal/project/common"
2020
"github.com/siderolabs/kres/internal/project/golang"
21+
"github.com/siderolabs/kres/internal/project/helm"
2122
"github.com/siderolabs/kres/internal/project/meta"
2223
"github.com/siderolabs/kres/internal/project/service"
2324
"github.com/siderolabs/kres/internal/project/wrap"
@@ -235,7 +236,10 @@ func (builder *builder) BuildGolang() error {
235236
// add common linter tools
236237
linters := golang.NewLinters(builder.meta)
237238

238-
toolchain.AddInput(generate, deepcopy, linters)
239+
// add helm-docs tool
240+
helmDocs := helm.NewHelmDocs(builder.meta)
241+
242+
toolchain.AddInput(generate, deepcopy, linters, helmDocs)
239243

240244
builder.lintInputs = append(builder.lintInputs, toolchain, linters)
241245

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package common
6+
7+
import (
8+
"github.com/siderolabs/kres/internal/config"
9+
"github.com/siderolabs/kres/internal/dag"
10+
"github.com/siderolabs/kres/internal/output/makefile"
11+
"github.com/siderolabs/kres/internal/project/meta"
12+
)
13+
14+
// CheckDirty builds Makefile `check-dirty` target.
15+
type CheckDirty struct { //nolint:govet
16+
dag.BaseNode
17+
18+
meta *meta.Options
19+
}
20+
21+
// NewCheckDirty initializes CheckDirty.
22+
func NewCheckDirty(meta *meta.Options) *CheckDirty {
23+
return &CheckDirty{
24+
BaseNode: dag.NewBaseNode("check-dirty"),
25+
26+
meta: meta,
27+
}
28+
}
29+
30+
// CompileMakefile implements makefile.Compiler.
31+
func (c *CheckDirty) CompileMakefile(output *makefile.Output) error {
32+
if c.meta.ContainerImageFrontend != config.ContainerImageFrontendDockerfile {
33+
return nil
34+
}
35+
36+
output.Target("check-dirty").
37+
Script("@if test -n \"`git status --porcelain`\"; then echo \"Source tree is dirty\"; git status; git diff; exit 1 ; fi")
38+
39+
return nil
40+
}

internal/project/helm/build.go

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import (
1313

1414
"github.com/siderolabs/kres/internal/config"
1515
"github.com/siderolabs/kres/internal/dag"
16+
"github.com/siderolabs/kres/internal/output/dockerfile"
17+
"github.com/siderolabs/kres/internal/output/dockerfile/step"
18+
"github.com/siderolabs/kres/internal/output/dockerignore"
1619
"github.com/siderolabs/kres/internal/output/ghworkflow"
1720
"github.com/siderolabs/kres/internal/output/makefile"
1821
"github.com/siderolabs/kres/internal/project/meta"
@@ -33,6 +36,32 @@ func NewBuild(meta *meta.Options) *Build {
3336
}
3437
}
3538

39+
// CompileDockerfile implements dockerfile.Compiler.
40+
func (helm *Build) CompileDockerfile(output *dockerfile.Output) error {
41+
output.Stage("helm-docs-run").
42+
Description("runs helm-docs").
43+
From("base").
44+
Step(step.Copy(helm.meta.HelmChartDir, filepath.Join("/src", helm.meta.HelmChartDir))).
45+
Step(step.Run("helm-docs", "--badge-style=flat", "--template-files=README.md.gotpl").
46+
MountCache(filepath.Join(helm.meta.CachePath, "go-build"), helm.meta.GitHubRepository).
47+
MountCache(filepath.Join(helm.meta.CachePath, "helm-docs"), helm.meta.GitHubRepository, step.CacheLocked))
48+
49+
output.Stage("helm-docs").
50+
Description("clean helm-docs output").
51+
From("scratch").
52+
Step(step.Copy(filepath.Join("/src", helm.meta.HelmChartDir), helm.meta.HelmChartDir).From("helm-docs-run"))
53+
54+
return nil
55+
}
56+
57+
// CompileDockerignore implements dockerignore.Compiler.
58+
func (helm *Build) CompileDockerignore(output *dockerignore.Output) error {
59+
output.
60+
AllowLocalPath(helm.meta.HelmChartDir)
61+
62+
return nil
63+
}
64+
3665
// CompileMakefile implements makefile.Compiler.
3766
func (helm *Build) CompileMakefile(output *makefile.Output) error {
3867
helmReleaseScript := fmt.Sprintf(`@helm push $(ARTIFACTS)/%s-*.tgz oci://$(HELMREPO) 2>&1 | tee $(ARTIFACTS)/.digest
@@ -41,7 +70,8 @@ func (helm *Build) CompileMakefile(output *makefile.Output) error {
4170

4271
output.VariableGroup(makefile.VariableGroupCommon).
4372
Variable(makefile.OverridableVariable("HELMREPO", "$(REGISTRY)/$(USERNAME)/charts")).
44-
Variable(makefile.OverridableVariable("COSIGN_ARGS", ""))
73+
Variable(makefile.OverridableVariable("COSIGN_ARGS", "")).
74+
Variable(makefile.OverridableVariable("HELMDOCS_VERSION", config.HelmDocsVersion))
4575

4676
generateTarget := output.GetTarget("generate")
4777
if generateTarget != nil {
@@ -67,7 +97,10 @@ func (helm *Build) CompileMakefile(output *makefile.Output) error {
6797
output.Target("helm-plugin-install").
6898
Description("Install helm plugins").
6999
Phony().
70-
Script(fmt.Sprintf("-helm plugin install https://github.com/helm-unittest/helm-unittest.git --verify=false --version=%s", config.HelmUnitTestVersion))
100+
Script(
101+
fmt.Sprintf("-helm plugin install https://github.com/helm-unittest/helm-unittest.git --verify=false --version=%s", config.HelmUnitTestVersion),
102+
fmt.Sprintf("-helm plugin install https://github.com/losisin/helm-values-schema-json.git --verify=false --version=%s", config.HelmValuesSchemaJSONVersion),
103+
)
71104

72105
output.Target("kuttl-plugin-install").
73106
Description("Install kubectl kuttl plugin").
@@ -84,6 +117,14 @@ func (helm *Build) CompileMakefile(output *makefile.Output) error {
84117
Phony().
85118
Script(fmt.Sprintf("@helm unittest %s --output-type junit --output-file $(ARTIFACTS)/helm-unittest-report.xml", helm.meta.HelmChartDir))
86119

120+
output.Target("chart-gen-schema").
121+
Description("Generate helm chart schema").
122+
Phony().
123+
Script(fmt.Sprintf("@helm schema --use-helm-docs --draft=7 --indent=2 --values=%s/values.yaml --output=%s/values.schema.json", helm.meta.HelmChartDir, helm.meta.HelmChartDir))
124+
125+
output.Target("helm-docs").Description("Runs helm-docs and generates chart documentation").
126+
Script("@$(MAKE) local-$@ DEST=.")
127+
87128
return nil
88129
}
89130

@@ -145,6 +186,27 @@ func (helm *Build) CompileGitHubWorkflow(output *ghworkflow.Output) error {
145186
return err
146187
}
147188

189+
schemaStep := ghworkflow.Step("Generate schema").
190+
SetMakeStep("chart-gen-schema")
191+
192+
if err := schemaStep.SetConditions("on-pull-request"); err != nil {
193+
return err
194+
}
195+
196+
docsStep := ghworkflow.Step("Generate docs").
197+
SetMakeStep("helm-docs")
198+
199+
if err := docsStep.SetConditions("on-pull-request"); err != nil {
200+
return err
201+
}
202+
203+
checkDirtyStep := ghworkflow.Step("Check dirty").
204+
SetMakeStep("check-dirty")
205+
206+
if err := checkDirtyStep.SetConditions("on-pull-request"); err != nil {
207+
return err
208+
}
209+
148210
helmLoginStep := ghworkflow.Step("helm login").
149211
SetEnv("HELM_CONFIG_HOME", "/var/tmp/.config/helm").
150212
SetCommand(fmt.Sprintf("helm registry login -u %s -p ${{ secrets.GITHUB_TOKEN }} ghcr.io", "${{ github.repository_owner }}"))
@@ -202,6 +264,9 @@ func (helm *Build) CompileGitHubWorkflow(output *ghworkflow.Output) error {
202264
templateStep,
203265
unittestPluginInstallStep,
204266
unittestStep,
267+
schemaStep,
268+
docsStep,
269+
checkDirtyStep,
205270
helmLoginStep,
206271
helmReleaseStep,
207272
},

internal/project/helm/helm_docs.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
package helm
6+
7+
import (
8+
"fmt"
9+
"path/filepath"
10+
11+
"github.com/siderolabs/kres/internal/dag"
12+
"github.com/siderolabs/kres/internal/output/dockerfile"
13+
"github.com/siderolabs/kres/internal/output/dockerfile/step"
14+
"github.com/siderolabs/kres/internal/project/meta"
15+
)
16+
17+
// HelmDocs is a helm-docs node.
18+
type HelmDocs struct {
19+
meta *meta.Options
20+
dag.BaseNode
21+
}
22+
23+
// NewHelmDocs initializes HelmDocs.
24+
func NewHelmDocs(meta *meta.Options) *HelmDocs {
25+
meta.BuildArgs.Add(
26+
"HELMDOCS_VERSION",
27+
)
28+
29+
return &HelmDocs{
30+
meta: meta,
31+
BaseNode: dag.NewBaseNode("helm-docs"),
32+
}
33+
}
34+
35+
// ToolchainBuild implements common.ToolchainBuilder hook.
36+
func (helm *HelmDocs) ToolchainBuild(stage *dockerfile.Stage) error {
37+
stage.
38+
Step(step.Arg("HELMDOCS_VERSION")).
39+
Step(step.Script(
40+
fmt.Sprintf(
41+
"go install github.com/norwoodj/helm-docs/cmd/helm-docs@${HELMDOCS_VERSION} \\\n"+
42+
"\t&& mv /go/bin/helm-docs %s/helm-docs", helm.meta.BinPath),
43+
).
44+
MountCache(filepath.Join(helm.meta.CachePath, "go-build"), helm.meta.GitHubRepository).
45+
MountCache(filepath.Join(helm.meta.GoPath, "pkg"), helm.meta.GitHubRepository),
46+
)
47+
48+
return nil
49+
}

0 commit comments

Comments
 (0)