mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-22 13:39:24 -06:00
add delta markdown generator
Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
107
docs/helpers/env-var-delta.go
Normal file
107
docs/helpers/env-var-delta.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rogpeppe/go-internal/semver"
|
||||
"gopkg.in/yaml.v2"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
const envVarYamlSource = "env_vars.yaml"
|
||||
|
||||
var envVarOutPutTemplates = map[string]string{
|
||||
"added": "templates/env-vars-added.md.tmpl",
|
||||
"removed": "templates/env-vars-removed.md.tmpl",
|
||||
"deprecated": "templates/env-vars-deprecated.md.tmpl",
|
||||
}
|
||||
|
||||
// ConfigField represents the env-var annotation in the code
|
||||
type ConfigField struct {
|
||||
Name string `yaml:"name"`
|
||||
DefaultValue string `yaml:"defaultValue"`
|
||||
Type string `yaml:"type"`
|
||||
Description string `yaml:"description"`
|
||||
IntroductionVersion string `yaml:"introductionVersion"`
|
||||
DeprecationVersion string `yaml:"deprecationVersion"`
|
||||
RemovalVersion string `yaml:"removalVersion"`
|
||||
DeprecationInfo string `yaml:"deprecationInfo"`
|
||||
}
|
||||
|
||||
type TemplateData struct {
|
||||
StartVersion string
|
||||
EndVersion string
|
||||
DeltaFields []*ConfigField
|
||||
}
|
||||
|
||||
// RenderEnvVarDeltaTable generates tables for env-var deltas
|
||||
func RenderEnvVarDeltaTable(osArgs []string) {
|
||||
if !semver.IsValid(osArgs[2]) {
|
||||
log.Fatalf("Start version invalid semver: %s", osArgs[2])
|
||||
}
|
||||
if !semver.IsValid(osArgs[3]) {
|
||||
log.Fatalf("Target version invalid semver: %s", osArgs[3])
|
||||
}
|
||||
startVersion := osArgs[2]
|
||||
endVersion := osArgs[3]
|
||||
fmt.Printf("Generating tables for env-var deltas between version %s and %s...\n", startVersion, endVersion)
|
||||
curdir, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fullYamlPath := filepath.Join(curdir, envVarYamlSource)
|
||||
configFields := make(map[string]*ConfigField)
|
||||
variableList := map[string][]*ConfigField{
|
||||
"added": {},
|
||||
"removed": {},
|
||||
"deprecated": {},
|
||||
}
|
||||
fmt.Printf("Reading existing variable definitions from %s\n", fullYamlPath)
|
||||
yfile, err := os.ReadFile(fullYamlPath)
|
||||
if err == nil {
|
||||
err := yaml.Unmarshal(yfile, configFields)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
fmt.Printf("Success, found %d entries\n", len(configFields))
|
||||
for _, field := range configFields {
|
||||
if field.DeprecationVersion != "" {
|
||||
fmt.Printf("Processing field %s\n", field.Name)
|
||||
}
|
||||
if field.RemovalVersion != "" && semver.Compare(startVersion, field.RemovalVersion) < 0 && semver.Compare(endVersion, field.RemovalVersion) >= 0 {
|
||||
variableList["removed"] = append(variableList["removed"], field)
|
||||
}
|
||||
if field.DeprecationVersion != "" && semver.Compare(startVersion, field.DeprecationVersion) <= 0 && semver.Compare(endVersion, field.DeprecationVersion) > 0 {
|
||||
variableList["deprecated"] = append(variableList["deprecated"], field)
|
||||
}
|
||||
if field.IntroductionVersion != "" && semver.Compare(startVersion, field.IntroductionVersion) <= 0 && semver.Compare(endVersion, field.IntroductionVersion) > 0 {
|
||||
variableList["added"] = append(variableList["added"], field)
|
||||
}
|
||||
}
|
||||
for templateName, templatePath := range envVarOutPutTemplates {
|
||||
content, err := os.ReadFile(templatePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
tpl := template.Must(template.New(templateName).Parse(string(content)))
|
||||
err = os.MkdirAll("output/env-deltas", 0700)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
targetFile, err := os.Create(filepath.Join("output/env-deltas", fmt.Sprintf("%s-%s-%s.md", startVersion, endVersion, templateName)))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = tpl.Execute(targetFile, TemplateData{
|
||||
StartVersion: startVersion,
|
||||
EndVersion: endVersion,
|
||||
DeltaFields: variableList[templateName],
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
14921
docs/helpers/env_vars.yaml
Normal file
14921
docs/helpers/env_vars.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,15 @@ func main() {
|
||||
RenderGlobalVarsTemplate()
|
||||
case "service-index":
|
||||
GenerateServiceIndexMarkdowns()
|
||||
case "env-var-delta-table":
|
||||
// This step is not covered by the all or default case, because it needs explicit arguments
|
||||
if len(os.Args) != 4 {
|
||||
fmt.Println("Needs two arguments: env-var-delta-table <first-version> <second-version>")
|
||||
fmt.Println("Example: env-var-delta-table v5.0.0 v6.0.0")
|
||||
fmt.Println("Will not generate usable results vor versions Prior to v5.0.0")
|
||||
} else {
|
||||
RenderEnvVarDeltaTable(os.Args)
|
||||
}
|
||||
case "all":
|
||||
RenderTemplates()
|
||||
GetRogueEnvs()
|
||||
@@ -24,7 +33,7 @@ func main() {
|
||||
case "help":
|
||||
fallthrough
|
||||
default:
|
||||
fmt.Println("Usage: [templates|rogue|globals|service-index|all]")
|
||||
fmt.Println("Usage: env-var-delta-table [templates|rogue|globals|service-index|env-var-delta-table|all|help]")
|
||||
}
|
||||
} else {
|
||||
// Left here, even though present in the switch case, for backwards compatibility
|
||||
|
||||
7
docs/helpers/templates/env-vars-added.md.tmpl
Normal file
7
docs/helpers/templates/env-vars-added.md.tmpl
Normal file
@@ -0,0 +1,7 @@
|
||||
Added between Version {{ .StartVersion }} and {{ .EndVersion }}.
|
||||
|
||||
| Variable | Description |
|
||||
| --- | --- |
|
||||
{{- range $key, $value := .DeltaFields}}
|
||||
| {{$value.Name}} | {{$value.Description}} |
|
||||
{{- end}}
|
||||
7
docs/helpers/templates/env-vars-deprecated.md.tmpl
Normal file
7
docs/helpers/templates/env-vars-deprecated.md.tmpl
Normal file
@@ -0,0 +1,7 @@
|
||||
Deprecated between Version {{ .StartVersion }} and {{ .EndVersion }}.
|
||||
|
||||
| Variable | Description | Deprecation Info |
|
||||
| --- | --- |
|
||||
{{- range $key, $value := .DeltaFields}}
|
||||
| {{$value.Name}} | {{$value.Description}} | {{$value.DeprecationInfo}} |
|
||||
{{- end}}
|
||||
7
docs/helpers/templates/env-vars-removed.md.tmpl
Normal file
7
docs/helpers/templates/env-vars-removed.md.tmpl
Normal file
@@ -0,0 +1,7 @@
|
||||
Removed between Version {{ .StartVersion }} and {{ .EndVersion }}.
|
||||
|
||||
| Variable | Description | Deprecation Info |
|
||||
| --- | --- |
|
||||
{{- range $key, $value := .DeltaFields}}
|
||||
| {{$value.Name}} | {{$value.Description}} | {{$value.DeprecationInfo}} |
|
||||
{{- end}}
|
||||
Reference in New Issue
Block a user