Skip to content

Commit

Permalink
docs: add new readme
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Urbanek <mateusz.urbanek.98@gmail.com>
  • Loading branch information
shanduur committed Nov 18, 2024
1 parent 9c290fd commit aef6c4d
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
cache: false
- run: |
make lint-manifests
- run: |
make \
generate-docs \
generate-schemas \
readme \
diff
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: backfill-all-app-versions generate-schemas generate-docs
all: backfill-all-app-versions generate-schemas generate-docs readme

##@ General

Expand All @@ -35,13 +35,17 @@ help: ## Display this help.
##@ Development

.PHONY: ci
ci: _ci _generate-schema _generate-docs
ci: _ci _generate-schema _generate-docs readme

.PHONY: _ci
_ci:
$(MAKE) _backfill-app-version CHART=${CHART}
$(MAKE) _set-chart-version VERSION=${VERSION}

.PHONY: readme
readme:
go run ./hack/readme

.PHONY: backfill-all-app-versions
backfill-all-app-versions: yq
for dir in anza-labs/*; do $(MAKE) _backfill-app-version CHART="$$dir"; done
Expand Down
9 changes: 9 additions & 0 deletions README.md
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) |
13 changes: 13 additions & 0 deletions README.md.gotpl
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 }}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/mikefarah/yq/v4 v4.44.5
github.com/norwoodj/helm-docs v1.14.2
golang.stackrox.io/kube-linter v0.7.1
gopkg.in/yaml.v3 v3.0.1
)

require (
Expand Down Expand Up @@ -146,7 +147,6 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
helm.sh/helm/v3 v3.16.2 // indirect
k8s.io/api v0.31.1 // indirect
k8s.io/apiextensions-apiserver v0.31.1 // indirect
Expand Down
109 changes: 109 additions & 0 deletions hack/readme/main.go
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
}

0 comments on commit aef6c4d

Please sign in to comment.