From b2a785f0254e65c75fd575960644a2bd713349ed Mon Sep 17 00:00:00 2001 From: nicholasSSUSE Date: Fri, 2 Aug 2024 17:11:38 -0300 Subject: [PATCH] new Update function for executing chart release/forward-port --- release/charts/charts.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/release/charts/charts.go b/release/charts/charts.go index 8380fb28..dcab934e 100644 --- a/release/charts/charts.go +++ b/release/charts/charts.go @@ -7,6 +7,8 @@ import ( "os/exec" "strings" + "github.com/go-git/go-git/v5" + "github.com/google/go-github/v39/github" "github.com/rancher/ecm-distro-tools/cmd/release/config" ) @@ -28,6 +30,42 @@ func List(ctx context.Context, c *config.ChartsRelease, branch, chart string) (s return response, nil } +// Update will pull the target chart version to the local branch and create a PR to release the chart +func Update(ctx context.Context, gh *github.Client, c *config.ChartsRelease, br, ch, vr string) (string, error) { + var branchArg, chartArg, versionArg, forkArg string + + branchArg = "--branch-version=" + br + chartArg = "--chart=" + ch + versionArg = "--version=" + vr + forkArg = "--fork=" + c.ChartsForkURL + + output, err := runChartsBuildScripts(c.Workspace, "release", branchArg, chartArg, versionArg, forkArg) + if err != nil { + return string(output), err + } + + r, err := git.PlainOpen(c.Workspace) + if err != nil { + return string(output), err + } + + wt, err := r.Worktree() + if err != nil { + return string(output), err + } + + if err := wt.AddWithOptions(&git.AddOptions{All: true}); err != nil { + return string(output), err + } + + commitMsg := "release chart: " + ch + " - version: " + vr + if _, err := wt.Commit(commitMsg, &git.CommitOptions{All: true}); err != nil { + return string(output), err + } + + return string(output), nil +} + func runChartsBuildScripts(chartsRepoPath string, args ...string) ([]byte, error) { // save current working dir ecmWorkDir, err := os.Getwd() @@ -45,7 +83,7 @@ func runChartsBuildScripts(chartsRepoPath string, args ...string) ([]byte, error cmd := exec.Command(bin, args...) output, err := cmd.CombinedOutput() if err != nil { - return []byte{}, err + return output, err } // Change back working dir for the caller