-
Notifications
You must be signed in to change notification settings - Fork 2
/
readme.go
67 lines (62 loc) · 1.21 KB
/
readme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//go:build readme
// +build readme
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"
"text/template"
)
func main() {
// Get Template filename
t, err := template.ParseFiles(os.Args[1])
if err != nil {
fmt.Println(err)
return
}
// Get Target filename
f, err := os.Create(os.Args[2])
defer f.Close()
if err != nil {
fmt.Println(err)
return
}
branch := os.Args[3]
chartsDir := os.Args[4]
files, _ := filepath.Glob("**/*/Chart.yaml")
var charts []map[string]string
for _, file := range files {
charts = append(charts, map[string]string{
"name": strings.Split(file, "/")[1],
"dir": chartsDir,
"version": extractVersion(file),
})
}
err = t.Execute(f, map[string]interface{}{
"charts": charts,
"masterBranch": branch == "master" || branch == "origin/master",
})
if err != nil {
fmt.Println(err)
return
}
}
func extractVersion(filepath string) string {
f, err := os.Open(filepath)
if err != nil {
fmt.Println(err)
return ""
}
defer f.Close()
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, "version: ") {
version := strings.TrimPrefix(line, "version: ")
return version
}
}
return ""
}