Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update.go updated version
Browse files Browse the repository at this point in the history
nicholasSUSE committed Aug 7, 2024
1 parent e765044 commit 7fb4b0b
Showing 1 changed file with 74 additions and 12 deletions.
86 changes: 74 additions & 12 deletions cmd/release/cmd/update.go
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log"

"github.com/rancher/ecm-distro-tools/release/charts"
"github.com/rancher/ecm-distro-tools/release/k3s"
@@ -45,33 +46,87 @@ var updateK3sReferencesCmd = &cobra.Command{
}

var updateChartsCmd = &cobra.Command{
Use: "charts [branch] [chart] [version]",
Short: "Update charts files locally, stage and commit the changes.",
RunE: func(cmd *cobra.Command, args []string) error {
var branch, chart, version string
Use: "charts [branch] [chart] [version]",
Short: "Update charts files locally, stage and commit the changes.",
Example: "release update charts 2.9 rancher-istio 104.0.0+up1.21.1",
Args: func(cmd *cobra.Command, args []string) error {
if err := validateChartConfig(); err != nil {
log.Fatal(err)
}

if len(args) < 3 {
return errors.New("expected at least three arguments: [branch] [chart] [version]")
if len(args) != 3 {
return errors.New("expected 3 arguments: [branch] [chart] [version]")
}

var branch, chart, version string
var found bool
var err error

branch = args[0]
chart = args[1]
version = args[2]

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")
found = charts.CheckBranchArgs(branch)
if !found {
return errors.New("branch not available: " + branch)
}

ctx := context.Background()
gh := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)
found, err = charts.CheckChartArgs(context.Background(), rootConfig.Charts, chart)
if err != nil {
return err
}
if !found {
return errors.New("chart not available: " + chart)
}

output, err := charts.Update(ctx, gh, config, branch, chart, version)
found, err = charts.CheckVersionArgs(context.Background(), rootConfig.Charts, chart, version)
if err != nil {
return err
}
if !found {
return errors.New("version not available: " + version)
}

return nil
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if err := validateChartConfig(); err != nil {
log.Fatal(err)
}

if len(args) == 0 {
return charts.BranchArgs(), cobra.ShellCompDirectiveNoFileComp
} else if len(args) == 1 {
chArgs, err := charts.ChartArgs(context.Background(), rootConfig.Charts)
if err != nil {
log.Fatalf("failed to get available charts: %v", err)
}

return chArgs, cobra.ShellCompDirectiveNoFileComp
} else if len(args) == 2 {
vArgs, err := charts.VersionArgs(context.Background(), rootConfig.Charts, args[1])
if err != nil {
log.Fatalf("failed to get available versions: %v", err)
}

return vArgs, cobra.ShellCompDirectiveNoFileComp
}

return nil, cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
var branch, chart, version string
branch = args[0]
chart = args[1]
version = args[2]

output, err := charts.Update(context.Background(), rootConfig.Charts, branch, chart, version)
if err != nil {
fmt.Println(output)
return err
}

fmt.Println(output)
return nil
},
}
@@ -82,3 +137,10 @@ func init() {
updateCmd.AddCommand(updateK3sCmd)
updateK3sCmd.AddCommand(updateK3sReferencesCmd)
}

func validateChartConfig() error {
if rootConfig.Charts.Workspace == "" || rootConfig.Charts.ChartsForkURL == "" {
return errors.New("verify your config file, chart configuration not implemented correctly, you must insert workspace path and your forked repo url")
}
return nil
}

0 comments on commit 7fb4b0b

Please sign in to comment.