Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasSUSE committed Aug 10, 2024
1 parent 7997ce0 commit c7ca76d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 51 deletions.
29 changes: 13 additions & 16 deletions cmd/release/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ var pushK3sTagsCmd = &cobra.Command{
}

var pushChartsCmd = &cobra.Command{
Use: "charts [release_branch] [debug (optional)]",
Use: "charts [branch-line] [debug (optional)]",
Short: "Push charts updates to remote upstream charts repository",
Example: "release push charts release-v2.9",
Example: "release push charts 2.9",
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.ReleaseBranches(), cobra.ShellCompDirectiveNoFileComp
return rootConfig.Charts.BranchLines, cobra.ShellCompDirectiveNoFileComp
}

return nil, cobra.ShellCompDirectiveNoFileComp
Expand All @@ -63,17 +63,15 @@ var pushChartsCmd = &cobra.Command{
}

if len(args) < 1 {
return errors.New("expected 1 argument: [release_branch]")
return errors.New("expected 1 argument: [branch-line]")
}

var (
releaseBranch string
found bool
)

releaseBranch = args[0]

found = charts.CheckReleaseBranchArgs(releaseBranch)
found = charts.IsBranchAvailable(args[0], rootConfig.Charts.BranchLines)
if !found {
return errors.New("release branch not available: " + releaseBranch)
}
Expand All @@ -82,17 +80,16 @@ var pushChartsCmd = &cobra.Command{
},
RunE: func(cmd *cobra.Command, args []string) error {
var (
releaseBranch string // given release branch
debug bool // debug mode
ctx context.Context // background context
t string // token
ghc *github.Client // github client
prURL string // created PR Url to be printed
err error
releaseBranch string // given release branch
debug bool // debug mode

ctx context.Context // background context
t string // token
ghc *github.Client // github client
)

// arguments
releaseBranch = args[0]
releaseBranch = charts.MountReleaseBranch(args[0])
if len(args) > 1 {
if args[1] == "debug" || args[1] == "d" {
debug = true
Expand All @@ -103,7 +100,7 @@ var pushChartsCmd = &cobra.Command{
t = rootConfig.Auth.GithubToken
ghc = repository.NewGithub(ctx, t)

prURL, err = charts.Push(ctx, rootConfig.Charts, rootConfig.User, ghc, releaseBranch, t, debug)
prURL, err := charts.Push(ctx, rootConfig.Charts, rootConfig.User, ghc, releaseBranch, t, debug)
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions release/charts/chart_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func VersionArgs(ctx context.Context, c *config.ChartsRelease, ch string) ([]str
return versions, nil
}

// MountReleaseBranch will mount the release branch name from the line provided
func MountReleaseBranch(line string) string {
return "release-v" + line
}

// IsBranchAvailable will check if the branch line exists
func IsBranchAvailable(branch string, availableBranches []string) bool {
for _, b := range availableBranches {
Expand Down
63 changes: 30 additions & 33 deletions release/charts/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,6 @@ func Update(ctx context.Context, c *config.ChartsRelease, br, ch, vr string) (st
return string(output), 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
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 {
return nil, errors.New(err.Error() + ": " + string(output))
}

// Change back working dir for the caller
if err := os.Chdir(ecmWorkDir); err != nil {
return nil, errors.New(err.Error() + ": " + string(output))
}

return output, nil
}

// Push will push the charts updates to the remote upstream charts repository
func Push(ctx context.Context, c *config.ChartsRelease, u *config.User, ghc *github.Client, b, t string, d bool) (string, error) {
const repoOwner = "rancher"
Expand All @@ -140,10 +112,9 @@ func Push(ctx context.Context, c *config.ChartsRelease, u *config.User, ghc *git
r *git.Repository // local opened repository
h *plumbing.Reference // local head reference
remote string // remote repository name
err error
)

r, err = git.PlainOpen(c.Workspace)
r, err := git.PlainOpen(c.Workspace)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -186,17 +157,43 @@ func Push(ctx context.Context, c *config.ChartsRelease, u *config.User, ghc *git
return prResp.GetHTMLURL(), 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
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 {
return nil, errors.New(err.Error() + ": " + string(output))
}

// Change back working dir for the caller
if err := os.Chdir(ecmWorkDir); err != nil {
return nil, errors.New(err.Error() + ": " + string(output))
}

return output, nil
}

// debugPullRequest will prompt the user to check the files and commits that will be pushed to the remote repository
func debugPullRequest(r *git.Repository, remote, b string) error {
var (
execute bool
iter object.CommitIter
err error
)

if execute = ecmExec.UserInput("Check files that will be pushed?"); execute {
// commit history
iter, err = r.Log(&git.LogOptions{})
iter, err := r.Log(&git.LogOptions{})
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,9 @@ func PushRemoteBranch(r *git.Repository, remote, u, t string, debug bool) error
var (
branchRef string
h *plumbing.Reference
err error
)

h, err = r.Head()
h, err := r.Head()
if err != nil {
return err
}
Expand Down

0 comments on commit c7ca76d

Please sign in to comment.