-
Notifications
You must be signed in to change notification settings - Fork 4
/
update.go
61 lines (54 loc) · 2.04 KB
/
update.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
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strings"
)
func main() {
d, err := os.ReadFile("charts/tmp.yaml")
if err != nil {
panic(err)
}
data := string(d)
//if condition string patch. The kustomize created a sub element to spec element since we cant add this block to the spec key directly. This bit
//will remove the sub element and indent this block back to the spec element
ifString := regexp.MustCompile("{{- if(.|\n)+{{- end }}").FindString(data)
ifIndentPatch := regexp.MustCompile("\n\\s\\s").ReplaceAllString(ifString, "\n")
data = regexp.MustCompile("\"\": \\|-\\s+").ReplaceAllString(data, "")
data = regexp.MustCompile("{{- if(.|\n)+({{- end }})").ReplaceAllString(data, ifIndentPatch)
data = strings.ReplaceAll(data, "'{{", "{{")
data = strings.ReplaceAll(data, "}}'", "}}")
data = strings.ReplaceAll(data, "{{ toYaml", "\n{{ toYaml")
data = regexp.MustCompile("{{\\s+").ReplaceAllString(data, "{{ ")
data = regexp.MustCompile("\\s+}}").ReplaceAllString(data, " }}")
if err = os.WriteFile("charts/tmp.yaml", []byte(data), 0644); err != nil {
panic(err)
}
c, err := os.ReadFile("charts/overwhelm/Chart.yaml")
if err != nil {
panic(err)
}
chart := string(c)
chartVersion := regexp.MustCompile("(version: )(.+)(\n)").FindSubmatch(c)[2]
scanner := bufio.NewScanner(os.Stdin)
fmt.Printf("The current chart version is %s. Provide the new version in the form of x.x.x if applicable or type NA if not upgrade is needed \n", chartVersion)
scanner.Scan()
text := scanner.Text()
if strings.ToLower(text) != "na" {
fmt.Printf("The new version will be version: %s. Type Yes to confirm: ", text)
scanner.Scan()
confirm := scanner.Text()
if strings.ToLower(confirm) != "yes" {
fmt.Printf("Ok, abandoning chart upgrade \n")
} else {
newVersion := "version: " + text
chart = strings.ReplaceAll(chart, "version: "+string(chartVersion), newVersion)
if err = os.WriteFile("charts/overwhelm/Chart.yaml", []byte(chart), 0644); err != nil {
panic(err)
}
fmt.Printf("Chart version upgraded to %s \n", text)
}
}
}