Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature implementation: release list charts #456

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cmd/release/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -40,8 +41,39 @@ 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]
}

briandowns marked this conversation as resolved.
Show resolved Hide resolved
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")
}

resp, err := charts.List(context.Background(), config, branch, chart)
if err != nil {
return err
}

fmt.Println(resp)
return nil
},
}

func init() {
rancherListSubCmd.AddCommand(rancherListRCDepsSubCmd)
listCmd.AddCommand(rancherListSubCmd)
listCmd.AddCommand(chartsListSubCmd)
rootCmd.AddCommand(listCmd)
}
57 changes: 57 additions & 0 deletions release/charts/charts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package charts

import (
"context"
"fmt"
"os"
"os/exec"
"strings"

"github.com/rancher/ecm-distro-tools/cmd/release/config"
)

// 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
if chart != "" {
chartArg = "--chart=" + chart
}

output, err := runChartsBuild(c.Workspace, "lifecycle-status", branchArg, chartArg)
if err != nil {
briandowns marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to: runChartsBuild. The previous name leaks implementation detail that could change in the future. This new name still conveys the idea and allows us to change from scripts to programs and exec model.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this isn't updating but it doesn't appear as though this has been completed.

return "", err
}

response := string(output) + fmt.Sprintf("\ngenerated log files for inspection at: \n%s\n", c.Workspace+"/logs/")
return response, nil
}

func runChartsBuild(chartsRepoPath string, args ...string) ([]byte, error) {
// save current working dir
ecmWorkDir, err := os.Getwd()
if err != nil {
return nil, err
}

// change working dir to the charts repo
briandowns marked this conversation as resolved.
Show resolved Hide resolved
if err := os.Chdir(chartsRepoPath); err != nil {
return nil, 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 {
briandowns marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

// Change back working dir for the caller
briandowns marked this conversation as resolved.
Show resolved Hide resolved
if err := os.Chdir(ecmWorkDir); err != nil {
return nil, err
}

return output, nil
}
Loading