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

#252: Add set charts branch refs command #271

Merged
merged 11 commits into from
Oct 13, 2023
6 changes: 3 additions & 3 deletions cmd/k3s_release/create_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (

"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func createTagsCommand() cli.Command {
return cli.Command{
func createTagsCommand() *cli.Command {
return &cli.Command{
Name: "create-tags",
Usage: "Create tags from kubernetes repo",
Flags: rootFlags,
Expand Down
20 changes: 11 additions & 9 deletions cmd/k3s_release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import (
"os"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

var rootFlags = []cli.Flag{
cli.StringFlag{
Name: "config",
Usage: "Specify release config file",
EnvVar: "RELEASE_CONFIG",
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Specify release config file",
EnvVars: []string{"RELEASE_CONFIG"},
},
cli.BoolFlag{
Name: "debug",
Usage: "Debug mode",
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Debug mode",
},
}

func main() {
app := cli.NewApp()
app.Name = "k3s-release"
app.Usage = "Perform a k3s release"
app.Commands = []cli.Command{
app.Commands = []*cli.Command{
createTagsCommand(),
pushTagsCommand(),
modifyK3SCommand(),
Expand Down
6 changes: 3 additions & 3 deletions cmd/k3s_release/modify_k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (

"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func modifyK3SCommand() cli.Command {
return cli.Command{
func modifyK3SCommand() *cli.Command {
return &cli.Command{
Name: "modify-k3s",
Usage: "Modify k3s go.mod with the updated tags and create a new PR",
Flags: rootFlags,
Expand Down
6 changes: 3 additions & 3 deletions cmd/k3s_release/push_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (

"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

const (
k3sRemote = "k3s-io"
)

func pushTagsCommand() cli.Command {
return cli.Command{
func pushTagsCommand() *cli.Command {
return &cli.Command{
Name: "push-tags",
Usage: "Push tags to speicifc remote",
Flags: rootFlags,
Expand Down
14 changes: 7 additions & 7 deletions cmd/k3s_release/tag_rc_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import (

"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func tagRCReleaseCommand() cli.Command {
return cli.Command{
Name: "tag-rc-release",
Usage: "tag rc release for k3s repo",
Flags: rootFlags,
Action: createRCRelease,
func tagRCReleaseCommand() *cli.Command {
return &cli.Command{
Name: "tag-rc-release",
Usage: "tag rc release for k3s repo",
Flags: rootFlags,
Action: createRCRelease,
}
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/k3s_release/tag_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (

"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func tagReleaseCommand() cli.Command {
return cli.Command{
func tagReleaseCommand() *cli.Command {
return &cli.Command{
Name: "tag-release",
Usage: "tag release for k3s repo",
Flags: rootFlags,
Expand Down
9 changes: 5 additions & 4 deletions cmd/rancher_release/check_rancher_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ import (

"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

const (
rancherOrg = "rancher"
rancherRepo = rancherOrg
)

func checkRancherImageCommand() cli.Command {
return cli.Command{
func checkRancherImageCommand() *cli.Command {
return &cli.Command{
Name: "check-rancher-image",
Usage: "check if rancher helm charts and docker images exist for a given image tag",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "tag",
Aliases: []string{"t"},
Usage: "release tag to validate image",
Required: true,
},
Expand Down
9 changes: 5 additions & 4 deletions cmd/rancher_release/list_images_rc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (

"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func listImagesRCCommand() cli.Command {
return cli.Command{
func listImagesRCCommand() *cli.Command {
return &cli.Command{
Name: "list-nonmirrored-rc-images",
Usage: "list all non-mirrored images which are in rc form given a tag in a MD format",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "tag",
Aliases: []string{"t"},
Usage: "release tag to validate images",
Required: true,
},
Expand Down
21 changes: 12 additions & 9 deletions cmd/rancher_release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@ import (
"os"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

var rootFlags = []cli.Flag{
cli.StringFlag{
Name: "config",
Usage: "Specify release config file",
EnvVar: "RELEASE_CONFIG",
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Specify release config file",
EnvVars: []string{"RELEASE_CONFIG"},
},
cli.BoolFlag{
Name: "debug",
Usage: "Debug mode",
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "Debug mode",
},
}

func main() {
app := cli.NewApp()
app.Name = "rancher-release"
app.Usage = "Perform a Rancher release"
app.Commands = []cli.Command{
app.Commands = []*cli.Command{
listImagesRCCommand(),
checkRancherImageCommand(),
setKDMBranchReferencesCommand(),
setChartsBranchReferencesCommand(),
}
app.Flags = rootFlags

Expand Down
88 changes: 88 additions & 0 deletions cmd/rancher_release/set_chart_branch_references.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package main

import (
"context"
"errors"

"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/urfave/cli/v2"
)

func setChartsBranchReferencesCommand() *cli.Command {
return &cli.Command{
Name: "set-charts-branch-refs",
Usage: "set charts branch references in files",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "fork-path",
Aliases: []string{"f"},
Usage: "rancher repo fork directory path",
Required: true,
},
&cli.StringFlag{
Name: "base-branch",
Aliases: []string{"b"},
Usage: "rancher branch to use as a base, e.g: release/v2.8",
Required: true,
},
&cli.StringFlag{
Name: "current-charts-branch",
Aliases: []string{"c"},
Usage: "current branch set for charts in the repo",
Required: true,
},
&cli.StringFlag{
Name: "new-charts-branch",
Aliases: []string{"n"},
Usage: "branch to be replaced in charts in the repo",
Required: true,
},
&cli.BoolFlag{
Name: "create-pr",
Aliases: []string{"p"},
Usage: "if true, a PR will be created from your fork to the rancher repo base branch and a variable 'GITHUB_TOKEN' must be exported",
},
&cli.StringFlag{
Name: "fork-owner",
Aliases: []string{"o"},
Usage: "github username of the owner of the fork, only required if 'create-pr' is true",
Required: false,
},
&cli.StringFlag{
Name: "github-token",
Aliases: []string{"g"},
Usage: "github token",
EnvVars: []string{"GITHUB_TOKEN"},
Required: false,
},
&cli.BoolFlag{
Name: "dry-run",
Aliases: []string{"r"},
Usage: "the newly created branch won't be pushed to remote and the PR won't be created",
Required: false,
},
},
Action: setChartBranchReferences,
}
}

func setChartBranchReferences(c *cli.Context) error {
forkPath := c.String("fork-path")
baseBranch := c.String("base-branch")
currentBranch := c.String("current-charts-branch")
newBranch := c.String("new-charts-branch")
createPR := c.Bool("create-pr")
forkOwner := c.String("fork-owner")
githubToken := c.String("github-token")
dryRun := c.Bool("dry-run")
if createPR {
if forkOwner == "" {
return errors.New("'create-pr' requires 'fork-owner'")
}
if githubToken == "" {
return errors.New("'create-pr' requires the 'GITHUB_TOKEN' env var")
}
}

return rancher.SetChartBranchReferences(context.Background(), forkPath, baseBranch, currentBranch, newBranch, forkOwner, githubToken, createPR, dryRun)
}
45 changes: 29 additions & 16 deletions cmd/rancher_release/set_kdm_branch_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,61 @@ package main
import (
"context"
"errors"
"os"

"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

func setKDMBranchReferencesCommand() cli.Command {
return cli.Command{
func setKDMBranchReferencesCommand() *cli.Command {
return &cli.Command{
Name: "set-kdm-branch-refs",
Usage: "set kdm branch references in files",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "fork-path",
Aliases: []string{"f"},
Usage: "rancher repo fork directory path",
Required: true,
},
cli.StringFlag{
&cli.StringFlag{
Name: "base-branch",
Aliases: []string{"b"},
Usage: "rancher branch to use as a base, e.g: release/v2.8",
Required: true,
},
cli.StringFlag{
&cli.StringFlag{
Name: "current-kdm-branch",
Aliases: []string{"c"},
Usage: "current kdm branch set in the repo",
Required: true,
},
cli.StringFlag{
&cli.StringFlag{
Name: "new-kdm-branch",
Aliases: []string{"n"},
Usage: "kdm branch to be replaced in the repo",
Required: true,
},
cli.BoolFlag{
Name: "create-pr",
Usage: "if true, a PR will be created from your fork to the rancher repo base branch and a variable 'GITHUB_TOKEN' must be exported",
&cli.BoolFlag{
Name: "create-pr",
Aliases: []string{"p"},
Usage: "if true, a PR will be created from your fork to the rancher repo base branch and a variable 'GITHUB_TOKEN' must be exported",
},
cli.StringFlag{
&cli.StringFlag{
Name: "fork-owner",
Aliases: []string{"o"},
Usage: "github username of the owner of the fork, only required if 'create-pr' is true",
Required: false,
},
cli.BoolFlag{
&cli.StringFlag{
Name: "github-token",
Aliases: []string{"g"},
Usage: "github token",
EnvVars: []string{"GITHUB_TOKEN"},
Required: false,
},
&cli.BoolFlag{
Name: "dry-run",
Aliases: []string{"r"},
Usage: "the newly created branch won't be pushed to remote and the PR won't be created",
Required: false,
},
Expand All @@ -58,10 +71,10 @@ func setKDMBranchReferences(c *cli.Context) error {
baseBranch := c.String("base-branch")
currentKDMBranch := c.String("current-kdm-branch")
newKDMBranch := c.String("new-kdm-branch")
createPR := c.BoolT("create-pr")
createPR := c.Bool("create-pr")
forkOwner := c.String("fork-owner")
githubToken := os.Getenv("GITHUB_TOKEN")
dryRun := c.BoolT("dry-run")
githubToken := c.String("github-token")
dryRun := c.Bool("dry-run")
if createPR {
if forkOwner == "" {
return errors.New("'create-pr' requires 'fork-owner'")
Expand Down
Loading