Skip to content

Commit

Permalink
new Update function for executing chart release/forward-port
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasSUSE committed Aug 2, 2024
1 parent 54ce841 commit b2a785f
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion release/charts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit b2a785f

Please sign in to comment.