@@ -12,14 +12,14 @@ import (
1212 "github.com/fatih/color"
1313)
1414
15- type Command string
15+ type DependencyCommand string
1616
1717const (
18- Build Command = "build"
19- Update Command = "update"
18+ Build DependencyCommand = "build"
19+ Update DependencyCommand = "update"
2020)
2121
22- func ManageDependencies (rootDir string , cmd Command ) error {
22+ func ManageDependencies (rootDir string , cmd DependencyCommand ) error {
2323 var charts []ChartInfo
2424 err := collectCharts (rootDir , & charts )
2525 if err != nil {
@@ -42,20 +42,40 @@ func ManageDependencies(rootDir string, cmd Command) error {
4242 fmt .Printf ("%s\n " , color .YellowString (stderr .String ()))
4343 }
4444
45- var successMsg string
46- if cmd == Build {
47- successMsg = "Successfully built"
48- } else {
49- successMsg = "Successfully updated"
45+ successMsg := fmt .Sprintf ("dependencies %sd successfully" , cmd )
46+ fmt .Printf ("%s %s\n " , color .BlueString (chart .Name ), successMsg )
47+ }
48+ return nil
49+ }
50+
51+ func LintCharts (rootDir string ) error {
52+ var charts []ChartInfo
53+ err := collectCharts (rootDir , & charts )
54+ if err != nil {
55+ return err
56+ }
57+
58+ for i := len (charts ) - 1 ; i >= 0 ; i -- {
59+ chart := charts [i ]
60+ helmCmd := exec .Command ("helm" , "lint" , chart .Path , "--values" , path .Join (rootDir , "values.yaml" ))
61+
62+ var stdout , stderr bytes.Buffer
63+ helmCmd .Stdout = & stdout
64+ helmCmd .Stderr = & stderr
65+
66+ if err := helmCmd .Run (); err != nil {
67+ return fmt .Errorf ("failed to lint chart %s:\n %s" , chart .Path , color .RedString (stderr .String ()))
68+ }
69+ if stderr .String () != "" {
70+ fmt .Printf ("%s\n " , color .YellowString (stderr .String ()))
5071 }
5172
52- fmt .Printf ("%s %s \n " , color .BlueString (chart .Name ), successMsg )
73+ fmt .Printf ("%s linted successfully \n " , color .BlueString (chart .Name ))
5374 }
5475 return nil
5576}
5677
5778func collectCharts (rootDir string , charts * []ChartInfo ) error {
58-
5979 _ , err := os .Stat (path .Join (rootDir , "Chart.yaml" ))
6080 if err != nil {
6181 return fmt .Errorf ("chart not found: %s" , rootDir )
0 commit comments