Skip to content

Commit 670be38

Browse files
committed
feat: updates default chart to add a footer to markdown files with the helm-docs version, if set
1 parent cbf9096 commit 670be38

File tree

10 files changed

+40
-4
lines changed

10 files changed

+40
-4
lines changed

cmd/helm-docs/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func retrieveInfoAndPrintDocumentation(chartDirectory string, chartSearchRoot st
2323
return
2424
}
2525

26-
document.PrintDocumentation(chartDocumentationInfo, chartSearchRoot, templateFiles, dryRun)
26+
document.PrintDocumentation(chartDocumentationInfo, chartSearchRoot, templateFiles, dryRun, version)
2727

2828
}
2929

example-charts/helm-3/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co
3939
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between |
4040
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
4141
| controller.service.type | string | `"LoadBalancer"` | |
42+
43+
----------------------------------------------
44+
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)

example-charts/nginx-ingress-but-auto-comments/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co
3939
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between. Do not set this below 2 |
4040
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
4141
| controller.service.type | string | `"LoadBalancer"` | |
42+
43+
----------------------------------------------
44+
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)

example-charts/nginx-ingress/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co
3939
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between |
4040
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
4141
| controller.service.type | string | `"LoadBalancer"` | |
42+
43+
----------------------------------------------
44+
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)

example-charts/no-requirements/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ A simple chart that installs, let's say PrometheusRules, that needs no sub-chart
2424
| rules.latency.percentiles.99.threshold | float | `1.5` | Threshold in seconds for our 99th percentile latency above which the alert will fire |
2525
| rules.statusCodes.codes.5xx.duration | string | `"5m"` | Duration for which the percent of 5xx responses must be above the threshold to alert |
2626
| rules.statusCodes.codes.5xx.threshold | float | `1.5` | Threshold percentage of 5xx responses above which the alert will fire |
27+
28+
----------------------------------------------
29+
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)

example-charts/special-characters-but-auto-comments/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ A chart demonstrating handling of special characters in values files
2525
| htmlSnippets.one | string | `"<html>\n <head></head>\n <body>\n <h1>Is this right, I don't know html</h1>\n </body>\n</html>\n"` | |
2626
| htmlSnippets.three | string | `"<html><head></head></html>"` | Another description |
2727
| htmlSnippets.two | string | `""` | Let's put it in the description <html></html> |
28+
29+
----------------------------------------------
30+
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)

example-charts/special-characters/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ A chart demonstrating handling of special characters in values files
2525
| htmlSnippets.one | string | `"<html>\n <head></head>\n <body>\n <h1>Is this right, I don't know html</h1>\n </body>\n</html>\n"` | |
2626
| htmlSnippets.three | string | `"<html><head></head></html>"` | Another description |
2727
| htmlSnippets.two | string | `""` | Let's put it in the description <html></html> |
28+
29+
----------------------------------------------
30+
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)

pkg/document/generate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func getOutputFile(chartDirectory string, dryRun bool) (*os.File, error) {
2727
return f, err
2828
}
2929

30-
func PrintDocumentation(chartDocumentationInfo helm.ChartDocumentationInfo, chartSearchRoot string, templateFiles []string, dryRun bool) {
30+
func PrintDocumentation(chartDocumentationInfo helm.ChartDocumentationInfo, chartSearchRoot string, templateFiles []string, dryRun bool, helmDocsVersion string) {
3131
log.Infof("Generating README Documentation for chart %s", chartDocumentationInfo.ChartDirectory)
3232

3333
chartDocumentationTemplate, err := newChartDocumentationTemplate(
@@ -41,7 +41,7 @@ func PrintDocumentation(chartDocumentationInfo helm.ChartDocumentationInfo, char
4141
return
4242
}
4343

44-
chartTemplateDataObject, err := getChartTemplateData(chartDocumentationInfo)
44+
chartTemplateDataObject, err := getChartTemplateData(chartDocumentationInfo, helmDocsVersion)
4545
if err != nil {
4646
log.Warnf("Error generating template data for chart %s: %s", chartDocumentationInfo.ChartDirectory, err)
4747
return

pkg/document/model.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ type valueRow struct {
1919

2020
type chartTemplateData struct {
2121
helm.ChartDocumentationInfo
22+
HelmDocsVersion string
2223
Values []valueRow
2324
}
2425

25-
func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo) (chartTemplateData, error) {
26+
func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo, helmDocsVersion string) (chartTemplateData, error) {
2627
// handle empty values file case
2728
if chartDocumentationInfo.ChartValues.Kind == 0 {
2829
return chartTemplateData{
@@ -52,6 +53,7 @@ func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo) (c
5253

5354
return chartTemplateData{
5455
ChartDocumentationInfo: chartDocumentationInfo,
56+
HelmDocsVersion: helmDocsVersion,
5557
Values: valuesTableRows,
5658
}, nil
5759
}

pkg/document/template.go

+16
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const defaultDocumentationTemplate = `{{ template "chart.header" . }}
3030
{{ template "chart.requirementsSection" . }}
3131
3232
{{ template "chart.valuesSection" . }}
33+
34+
{{ template "helm-docs.versionFooter" . }}
3335
`
3436

3537
func getNameTemplate() string {
@@ -209,6 +211,19 @@ func getValuesTableTemplates() string {
209211
return valuesSectionBuilder.String()
210212
}
211213

214+
func getHelmDocsVersionTemplates() string {
215+
versionSectionBuilder := strings.Builder{}
216+
versionSectionBuilder.WriteString(`{{ define "helm-docs.version" }}{{ if .HelmDocsVersion }}{{ .HelmDocsVersion }}{{ end }}{{ end }}`)
217+
versionSectionBuilder.WriteString(`{{ define "helm-docs.versionFooter" }}`)
218+
versionSectionBuilder.WriteString("\n{{ if .HelmDocsVersion }}\n")
219+
versionSectionBuilder.WriteString("----------------------------------------------\n")
220+
versionSectionBuilder.WriteString("Autogenerated from chart metadata using [helm-docs v{{ .HelmDocsVersion }}](https://github.com/norwoodj/helm-docs/releases/v{{ .HelmDocsVersion }})")
221+
versionSectionBuilder.WriteString("{{ end }}")
222+
versionSectionBuilder.WriteString("{{ end }}")
223+
224+
return versionSectionBuilder.String()
225+
}
226+
212227
func getDocumentationTemplate(chartDirectory string, chartSearchRoot string, templateFiles []string) (string, error) {
213228
templateFilesForChart := make([]string, 0)
214229

@@ -264,6 +279,7 @@ func getDocumentationTemplates(chartDirectory string, chartSearchRoot string, te
264279
getValuesTableTemplates(),
265280
getHomepageTemplate(),
266281
getMaintainersTemplate(),
282+
getHelmDocsVersionTemplates(),
267283
documentationTemplate,
268284
}, nil
269285
}

0 commit comments

Comments
 (0)