-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mateusz Urbanek <mateusz.urbanek.98@gmail.com>
- Loading branch information
Showing
6 changed files
with
139 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
# The Anza Labs Library for Kubernetes | ||
|
||
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/anza-labs)](https://artifacthub.io/packages/search?repo=anza-labs) | ||
|
||
## Helm Charts | ||
|
||
This repository contains the following Helm charts: | ||
|
||
| Name | Version | App Version | About | Artifact Hub | | ||
|------|---------|-------------|-------|--------------| | ||
| [lubelogger](anza-labs/lubelogger) | `0.4.9` | `v1.4.0` | LubeLogger is a web-based vehicle maintenance and fuel mileage tracker | [![Artifact Hub](https://img.shields.io/static/v1?label=ArtifactHub&message=View&color=informational)](https://artifacthub.io/packages/helm/anza-labs/lubelogger) | | ||
| [scribe](anza-labs/scribe) | `0.1.4` | `v0.1.1` | Scribe is a tool that automates the propagation of annotations across Kubernetes resources based on the annotations in a Namespace. | [![Artifact Hub](https://img.shields.io/static/v1?label=ArtifactHub&message=View&color=informational)](https://artifacthub.io/packages/helm/anza-labs/scribe) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# The Anza Labs Library for Kubernetes | ||
|
||
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/anza-labs)](https://artifacthub.io/packages/search?repo=anza-labs) | ||
|
||
## Helm Charts | ||
|
||
This repository contains the following Helm charts: | ||
|
||
| Name | Version | App Version | About | Artifact Hub | | ||
|------|---------|-------------|-------|--------------| | ||
{{- range . }} | ||
| [{{ .Name }}](anza-labs/{{ .Name }}) | `{{ .Version }}` | `{{ .AppVersion }}` | {{ .Description }} | [![Artifact Hub](https://img.shields.io/static/v1?label=ArtifactHub&message=View&color=informational)](https://artifacthub.io/packages/helm/anza-labs/{{ .Name }}) | | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"text/template" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
const ( | ||
readmeTemplateFile = "./README.md.gotpl" | ||
chartsDir = "./anza-labs" | ||
) | ||
|
||
// Chart represents the structure of a Chart.yaml file. | ||
type Chart struct { | ||
Name string `yaml:"name"` | ||
Version string `yaml:"version"` | ||
AppVersion string `yaml:"appVersion"` | ||
Description string `yaml:"description"` | ||
} | ||
|
||
func main() { | ||
charts, err := loadCharts(chartsDir) | ||
if err != nil { | ||
log.Fatalf("Error loading charts: %v", err) | ||
} | ||
|
||
readme, err := renderReadme(charts) | ||
if err != nil { | ||
log.Fatalf("Error rendering README: %v", err) | ||
} | ||
|
||
err = os.WriteFile("README.md", []byte(readme), 0644) | ||
if err != nil { | ||
log.Fatalf("Error writing README.md: %v", err) | ||
} | ||
|
||
log.Print("README.md generated successfully.") | ||
} | ||
|
||
// loadCharts recursively loads all Chart.yaml files from the given directory. | ||
func loadCharts(dir string) ([]Chart, error) { | ||
var charts []Chart | ||
|
||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() || filepath.Base(path) != "Chart.yaml" { | ||
return nil | ||
} | ||
|
||
chart, err := loadChart(path) | ||
if err != nil { | ||
return fmt.Errorf("failed to load %s: %w", path, err) | ||
} | ||
charts = append(charts, chart) | ||
return nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return charts, nil | ||
} | ||
|
||
// loadChart parses a single Chart.yaml file into a Chart struct. | ||
func loadChart(path string) (Chart, error) { | ||
data, err := os.ReadFile(path) | ||
if err != nil { | ||
return Chart{}, err | ||
} | ||
|
||
var chart Chart | ||
if err := yaml.Unmarshal(data, &chart); err != nil { | ||
return Chart{}, err | ||
} | ||
|
||
chart.Description = strings.ReplaceAll(chart.Description, "\n", " ") | ||
chart.Description = strings.ReplaceAll(chart.Description, "\r", " ") | ||
|
||
return chart, nil | ||
} | ||
|
||
// renderReadme generates the README.md content using the charts data. | ||
func renderReadme(charts []Chart) (string, error) { | ||
readmeTemplate, err := os.ReadFile(readmeTemplateFile) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
tmpl, err := template.New("readme").Parse(string(readmeTemplate)) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var buf bytes.Buffer | ||
if err := tmpl.Execute(&buf, charts); err != nil { | ||
return "", err | ||
} | ||
|
||
return buf.String(), nil | ||
} |