Skip to content

Commit

Permalink
Merge pull request #63 from norwoodj/add-helm-docs-version-line
Browse files Browse the repository at this point in the history
feat: updates default chart to add a footer to markdown files with th…
  • Loading branch information
norwoodj committed Oct 4, 2020
2 parents cbf9096 + 670be38 commit 0dc6df7
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/helm-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func retrieveInfoAndPrintDocumentation(chartDirectory string, chartSearchRoot st
return
}

document.PrintDocumentation(chartDocumentationInfo, chartSearchRoot, templateFiles, dryRun)
document.PrintDocumentation(chartDocumentationInfo, chartSearchRoot, templateFiles, dryRun, version)

}

Expand Down
3 changes: 3 additions & 0 deletions example-charts/helm-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between |
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
| controller.service.type | string | `"LoadBalancer"` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)
3 changes: 3 additions & 0 deletions example-charts/nginx-ingress-but-auto-comments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between. Do not set this below 2 |
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
| controller.service.type | string | `"LoadBalancer"` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)
3 changes: 3 additions & 0 deletions example-charts/nginx-ingress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ A simple wrapper around the stable/nginx-ingress chart that adds a few of our co
| controller.replicas | int | `nil` | Number of nginx-ingress pods to load balance between |
| controller.service.annotations."external-dns.alpha.kubernetes.io/hostname" | string | `"stupidchess.jmn23.com"` | Hostname to be assigned to the ELB for the service |
| controller.service.type | string | `"LoadBalancer"` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)
3 changes: 3 additions & 0 deletions example-charts/no-requirements/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ A simple chart that installs, let's say PrometheusRules, that needs no sub-chart
| rules.latency.percentiles.99.threshold | float | `1.5` | Threshold in seconds for our 99th percentile latency above which the alert will fire |
| rules.statusCodes.codes.5xx.duration | string | `"5m"` | Duration for which the percent of 5xx responses must be above the threshold to alert |
| rules.statusCodes.codes.5xx.threshold | float | `1.5` | Threshold percentage of 5xx responses above which the alert will fire |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)
3 changes: 3 additions & 0 deletions example-charts/special-characters-but-auto-comments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ A chart demonstrating handling of special characters in values files
| 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"` | |
| htmlSnippets.three | string | `"<html><head></head></html>"` | Another description |
| htmlSnippets.two | string | `""` | Let's put it in the description <html></html> |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)
3 changes: 3 additions & 0 deletions example-charts/special-characters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ A chart demonstrating handling of special characters in values files
| 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"` | |
| htmlSnippets.three | string | `"<html><head></head></html>"` | Another description |
| htmlSnippets.two | string | `""` | Let's put it in the description <html></html> |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.1.0](https://github.com/norwoodj/helm-docs/releases/1.1.0)
4 changes: 2 additions & 2 deletions pkg/document/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func getOutputFile(chartDirectory string, dryRun bool) (*os.File, error) {
return f, err
}

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

chartDocumentationTemplate, err := newChartDocumentationTemplate(
Expand All @@ -41,7 +41,7 @@ func PrintDocumentation(chartDocumentationInfo helm.ChartDocumentationInfo, char
return
}

chartTemplateDataObject, err := getChartTemplateData(chartDocumentationInfo)
chartTemplateDataObject, err := getChartTemplateData(chartDocumentationInfo, helmDocsVersion)
if err != nil {
log.Warnf("Error generating template data for chart %s: %s", chartDocumentationInfo.ChartDirectory, err)
return
Expand Down
4 changes: 3 additions & 1 deletion pkg/document/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ type valueRow struct {

type chartTemplateData struct {
helm.ChartDocumentationInfo
HelmDocsVersion string
Values []valueRow
}

func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo) (chartTemplateData, error) {
func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo, helmDocsVersion string) (chartTemplateData, error) {
// handle empty values file case
if chartDocumentationInfo.ChartValues.Kind == 0 {
return chartTemplateData{
Expand Down Expand Up @@ -52,6 +53,7 @@ func getChartTemplateData(chartDocumentationInfo helm.ChartDocumentationInfo) (c

return chartTemplateData{
ChartDocumentationInfo: chartDocumentationInfo,
HelmDocsVersion: helmDocsVersion,
Values: valuesTableRows,
}, nil
}
16 changes: 16 additions & 0 deletions pkg/document/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const defaultDocumentationTemplate = `{{ template "chart.header" . }}
{{ template "chart.requirementsSection" . }}
{{ template "chart.valuesSection" . }}
{{ template "helm-docs.versionFooter" . }}
`

func getNameTemplate() string {
Expand Down Expand Up @@ -209,6 +211,19 @@ func getValuesTableTemplates() string {
return valuesSectionBuilder.String()
}

func getHelmDocsVersionTemplates() string {
versionSectionBuilder := strings.Builder{}
versionSectionBuilder.WriteString(`{{ define "helm-docs.version" }}{{ if .HelmDocsVersion }}{{ .HelmDocsVersion }}{{ end }}{{ end }}`)
versionSectionBuilder.WriteString(`{{ define "helm-docs.versionFooter" }}`)
versionSectionBuilder.WriteString("\n{{ if .HelmDocsVersion }}\n")
versionSectionBuilder.WriteString("----------------------------------------------\n")
versionSectionBuilder.WriteString("Autogenerated from chart metadata using [helm-docs v{{ .HelmDocsVersion }}](https://github.com/norwoodj/helm-docs/releases/v{{ .HelmDocsVersion }})")
versionSectionBuilder.WriteString("{{ end }}")
versionSectionBuilder.WriteString("{{ end }}")

return versionSectionBuilder.String()
}

func getDocumentationTemplate(chartDirectory string, chartSearchRoot string, templateFiles []string) (string, error) {
templateFilesForChart := make([]string, 0)

Expand Down Expand Up @@ -264,6 +279,7 @@ func getDocumentationTemplates(chartDirectory string, chartSearchRoot string, te
getValuesTableTemplates(),
getHomepageTemplate(),
getMaintainersTemplate(),
getHelmDocsVersionTemplates(),
documentationTemplate,
}, nil
}
Expand Down

0 comments on commit 0dc6df7

Please sign in to comment.