From c4404375f66542cd066a3365662c83a56c6ae529 Mon Sep 17 00:00:00 2001 From: nicholasSSUSE Date: Fri, 26 Jul 2024 18:12:47 -0300 Subject: [PATCH 1/5] adding release list charts sub command --- cmd/release/cmd/list.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cmd/release/cmd/list.go b/cmd/release/cmd/list.go index 57bc4a29..a0c27e8a 100644 --- a/cmd/release/cmd/list.go +++ b/cmd/release/cmd/list.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" + "github.com/rancher/ecm-distro-tools/release/charts" "github.com/rancher/ecm-distro-tools/release/rancher" "github.com/spf13/cobra" ) @@ -40,8 +41,38 @@ var rancherListRCDepsSubCmd = &cobra.Command{ }, } +var chartsListSubCmd = &cobra.Command{ + Use: "charts [branch] [charts](optional)", + Short: "List Charts assets versions state for release process", + RunE: func(cmd *cobra.Command, args []string) error { + + var branch, chart string = "", "" + + if len(args) < 1 { + return errors.New("expected at least one argument: [branch]") + } + branch = args[0] + + if len(args) > 1 { + chart = args[1] + } + + config := rootConfig.Charts + if config.Workspace == "" || config.ChartsForkURL == "" { + return errors.New("verify your config file, chart configuration not implemented correctly, you must insert workspace path and your forked repo url") + } + + err := charts.ListLifecycleStatus(context.Background(), config, branch, chart) + if err != nil { + return err + } + return nil + }, +} + func init() { rancherListSubCmd.AddCommand(rancherListRCDepsSubCmd) listCmd.AddCommand(rancherListSubCmd) + listCmd.AddCommand(chartsListSubCmd) rootCmd.AddCommand(listCmd) } From 2ef133de5910f38fe2345577c4440c2d455acfbb Mon Sep 17 00:00:00 2001 From: nicholasSSUSE Date: Fri, 26 Jul 2024 18:13:36 -0300 Subject: [PATCH 2/5] adding charts release package with direct execution to charts-build-scripts binary --- release/charts/charts.go | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 release/charts/charts.go diff --git a/release/charts/charts.go b/release/charts/charts.go new file mode 100644 index 00000000..c5a0df2b --- /dev/null +++ b/release/charts/charts.go @@ -0,0 +1,61 @@ +package charts + +import ( + "context" + "fmt" + "os" + "os/exec" + "strings" + + ecmConfig "github.com/rancher/ecm-distro-tools/cmd/release/config" +) + +// ListLifecycleStatus prints the lifecycle status of the charts +func ListLifecycleStatus(ctx context.Context, c *ecmConfig.ChartsRelease, branch, chart string) error { + + var branchArg, chartArg string = "", "" + + branchArg = "--branch-version=" + branch + if chart != "" { + chartArg = "--chart=" + chart + } + + err := executeChartsBuildScripts(c.Workspace, "lifecycle-status", branchArg, chartArg) + if err != nil { + return err + } + + fmt.Printf("generated log files for inspection at: \n%s\n", c.Workspace+"/logs/") + return nil +} + +func executeChartsBuildScripts(chartsRepoPath string, args ...string) error { + // save current working dir + ecmWorkDir, err := os.Getwd() + if err != nil { + return err + } + + // change working dir to the charts repo + err = os.Chdir(chartsRepoPath) + if err != nil { + return err + } + + bin := strings.Join([]string{chartsRepoPath, "bin", "charts-build-scripts"}, string(os.PathSeparator)) + + cmd := exec.Command(bin, args...) + output, err := cmd.CombinedOutput() + if err != nil { + return fmt.Errorf("failed to execute charts-build-scripts: %w, output: %s", err, output) + } + fmt.Printf("charts-build-scripts output: %s\n", output) + + // Change back working dir for the caller + err = os.Chdir(ecmWorkDir) + if err != nil { + return err + } + + return nil +} From cd5720a831e864be4c415ad20e33696308d4e467 Mon Sep 17 00:00:00 2001 From: nicholasSSUSE Date: Fri, 26 Jul 2024 18:36:56 -0300 Subject: [PATCH 3/5] fixes --- cmd/release/cmd/list.go | 8 ++------ release/charts/charts.go | 29 +++++++++++++---------------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/cmd/release/cmd/list.go b/cmd/release/cmd/list.go index a0c27e8a..e94a82cb 100644 --- a/cmd/release/cmd/list.go +++ b/cmd/release/cmd/list.go @@ -46,7 +46,7 @@ var chartsListSubCmd = &cobra.Command{ Short: "List Charts assets versions state for release process", RunE: func(cmd *cobra.Command, args []string) error { - var branch, chart string = "", "" + var branch, chart string if len(args) < 1 { return errors.New("expected at least one argument: [branch]") @@ -62,11 +62,7 @@ var chartsListSubCmd = &cobra.Command{ return errors.New("verify your config file, chart configuration not implemented correctly, you must insert workspace path and your forked repo url") } - err := charts.ListLifecycleStatus(context.Background(), config, branch, chart) - if err != nil { - return err - } - return nil + return charts.ListLifecycleStatus(context.Background(), config, branch, chart) }, } diff --git a/release/charts/charts.go b/release/charts/charts.go index c5a0df2b..3f1e2ca1 100644 --- a/release/charts/charts.go +++ b/release/charts/charts.go @@ -7,39 +7,38 @@ import ( "os/exec" "strings" - ecmConfig "github.com/rancher/ecm-distro-tools/cmd/release/config" + "github.com/rancher/ecm-distro-tools/cmd/release/config" ) // ListLifecycleStatus prints the lifecycle status of the charts -func ListLifecycleStatus(ctx context.Context, c *ecmConfig.ChartsRelease, branch, chart string) error { - - var branchArg, chartArg string = "", "" +func ListLifecycleStatus(ctx context.Context, c *config.ChartsRelease, branch, chart string) error { + var branchArg, chartArg string branchArg = "--branch-version=" + branch if chart != "" { chartArg = "--chart=" + chart } - err := executeChartsBuildScripts(c.Workspace, "lifecycle-status", branchArg, chartArg) + output, err := runChartsBuildScripts(c.Workspace, "lifecycle-status", branchArg, chartArg) if err != nil { return err } + fmt.Println(string(output)) fmt.Printf("generated log files for inspection at: \n%s\n", c.Workspace+"/logs/") return nil } -func executeChartsBuildScripts(chartsRepoPath string, args ...string) error { +func runChartsBuildScripts(chartsRepoPath string, args ...string) ([]byte, error) { // save current working dir ecmWorkDir, err := os.Getwd() if err != nil { - return err + return []byte{}, err } // change working dir to the charts repo - err = os.Chdir(chartsRepoPath) - if err != nil { - return err + if err := os.Chdir(chartsRepoPath); err != nil { + return []byte{}, err } bin := strings.Join([]string{chartsRepoPath, "bin", "charts-build-scripts"}, string(os.PathSeparator)) @@ -47,15 +46,13 @@ func executeChartsBuildScripts(chartsRepoPath string, args ...string) error { cmd := exec.Command(bin, args...) output, err := cmd.CombinedOutput() if err != nil { - return fmt.Errorf("failed to execute charts-build-scripts: %w, output: %s", err, output) + return []byte{}, err } - fmt.Printf("charts-build-scripts output: %s\n", output) // Change back working dir for the caller - err = os.Chdir(ecmWorkDir) - if err != nil { - return err + if err := os.Chdir(ecmWorkDir); err != nil { + return []byte{}, err } - return nil + return output, nil } From f94a604130f7b1998e33371e63f6f42fea5ef6c1 Mon Sep 17 00:00:00 2001 From: nicholasSSUSE Date: Tue, 30 Jul 2024 18:02:22 -0300 Subject: [PATCH 4/5] fixes 2 --- cmd/release/cmd/list.go | 8 +++++++- release/charts/charts.go | 11 +++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/release/cmd/list.go b/cmd/release/cmd/list.go index e94a82cb..5b8762d9 100644 --- a/cmd/release/cmd/list.go +++ b/cmd/release/cmd/list.go @@ -62,7 +62,13 @@ var chartsListSubCmd = &cobra.Command{ return errors.New("verify your config file, chart configuration not implemented correctly, you must insert workspace path and your forked repo url") } - return charts.ListLifecycleStatus(context.Background(), config, branch, chart) + resp, err := charts.List(context.Background(), config, branch, chart) + if err != nil { + return err + } + + fmt.Println(resp) + return nil }, } diff --git a/release/charts/charts.go b/release/charts/charts.go index 3f1e2ca1..8380fb28 100644 --- a/release/charts/charts.go +++ b/release/charts/charts.go @@ -10,8 +10,8 @@ import ( "github.com/rancher/ecm-distro-tools/cmd/release/config" ) -// ListLifecycleStatus prints the lifecycle status of the charts -func ListLifecycleStatus(ctx context.Context, c *config.ChartsRelease, branch, chart string) error { +// List prints the lifecycle status of the charts +func List(ctx context.Context, c *config.ChartsRelease, branch, chart string) (string, error) { var branchArg, chartArg string branchArg = "--branch-version=" + branch @@ -21,12 +21,11 @@ func ListLifecycleStatus(ctx context.Context, c *config.ChartsRelease, branch, c output, err := runChartsBuildScripts(c.Workspace, "lifecycle-status", branchArg, chartArg) if err != nil { - return err + return "", err } - fmt.Println(string(output)) - fmt.Printf("generated log files for inspection at: \n%s\n", c.Workspace+"/logs/") - return nil + response := string(output) + fmt.Sprintf("\ngenerated log files for inspection at: \n%s\n", c.Workspace+"/logs/") + return response, nil } func runChartsBuildScripts(chartsRepoPath string, args ...string) ([]byte, error) { From 5abebe1dc504842de8de0ebed3e518cad5c7de15 Mon Sep 17 00:00:00 2001 From: nicholasSSUSE Date: Fri, 2 Aug 2024 17:42:09 -0300 Subject: [PATCH 5/5] fixes 3 --- cmd/release/cmd/list.go | 1 - release/charts/charts.go | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/release/cmd/list.go b/cmd/release/cmd/list.go index 5b8762d9..26dbc29c 100644 --- a/cmd/release/cmd/list.go +++ b/cmd/release/cmd/list.go @@ -45,7 +45,6 @@ var chartsListSubCmd = &cobra.Command{ Use: "charts [branch] [charts](optional)", Short: "List Charts assets versions state for release process", RunE: func(cmd *cobra.Command, args []string) error { - var branch, chart string if len(args) < 1 { diff --git a/release/charts/charts.go b/release/charts/charts.go index 8380fb28..588ac6ce 100644 --- a/release/charts/charts.go +++ b/release/charts/charts.go @@ -19,7 +19,7 @@ func List(ctx context.Context, c *config.ChartsRelease, branch, chart string) (s chartArg = "--chart=" + chart } - output, err := runChartsBuildScripts(c.Workspace, "lifecycle-status", branchArg, chartArg) + output, err := runChartsBuild(c.Workspace, "lifecycle-status", branchArg, chartArg) if err != nil { return "", err } @@ -28,16 +28,16 @@ func List(ctx context.Context, c *config.ChartsRelease, branch, chart string) (s return response, nil } -func runChartsBuildScripts(chartsRepoPath string, args ...string) ([]byte, error) { +func runChartsBuild(chartsRepoPath string, args ...string) ([]byte, error) { // save current working dir ecmWorkDir, err := os.Getwd() if err != nil { - return []byte{}, err + return nil, err } // change working dir to the charts repo if err := os.Chdir(chartsRepoPath); err != nil { - return []byte{}, err + return nil, err } bin := strings.Join([]string{chartsRepoPath, "bin", "charts-build-scripts"}, string(os.PathSeparator)) @@ -45,12 +45,12 @@ func runChartsBuildScripts(chartsRepoPath string, args ...string) ([]byte, error cmd := exec.Command(bin, args...) output, err := cmd.CombinedOutput() if err != nil { - return []byte{}, err + return nil, err } // Change back working dir for the caller if err := os.Chdir(ecmWorkDir); err != nil { - return []byte{}, err + return nil, err } return output, nil