Skip to content

Commit

Permalink
trim fat and address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
radTuti committed Dec 10, 2024
1 parent 0a3324e commit 7d53965
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 445 deletions.
126 changes: 63 additions & 63 deletions release/cmd/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,75 +38,75 @@ func branchCommand(cfg *Config) *cli.Command {

func branchSubCommands(cfg *Config) []*cli.Command {
return []*cli.Command{
cutReleaseBranchCommand(cfg),
cutOperatorBranchCommand(cfg),
}
}

// cutReleaseBranchCommand is a subcommand to cut a new release branch.
func cutReleaseBranchCommand(cfg *Config) *cli.Command {
baseBranchFlag := mainBranchFlag
baseBranchFlag.Usage = "The base branch to cut the release branch from"
baseBranchFlag.EnvVars = []string{"RELEASE_BRANCH_BASE"}

return &cli.Command{
Name: "cut",
Usage: fmt.Sprintf("Cut a new release branch from %s", utils.DefaultBranch),
Flags: append(gitFlags,
baseBranchFlag, releaseBranchPrefixFlag, devTagSuffixFlag,
publishBranchFlag, skipValidationFlag,
),
Action: func(c *cli.Context) error {
configureLogging("cut-branch.log")
// Cut a new release branch
{
Name: "cut",
Usage: fmt.Sprintf("Cut a new release branch from %s", utils.DefaultBranch),
Flags: []cli.Flag{
orgFlag,
repoFlag,
repoRemoteFlag,
baseBranchFlag,
releaseBranchPrefixFlag,
devTagSuffixFlag,
publishBranchFlag,
skipValidationFlag,
},
Action: func(c *cli.Context) error {
configureLogging("cut-branch.log")

m := branch.NewManager(
branch.WithRepoRoot(cfg.RepoRootDir),
branch.WithRepoRemote(c.String(repoRemoteFlag.Name)),
branch.WithMainBranch(c.String(mainBranchFlag.Name)),
branch.WithDevTagIdentifier(c.String(devTagSuffixFlag.Name)),
branch.WithReleaseBranchPrefix(c.String(releaseBranchPrefixFlag.Name)),
branch.WithValidate(!c.Bool(skipValidationFlag.Name)),
branch.WithPublish(c.Bool(publishBranchFlag.Name)))
return m.CutReleaseBranch()
m := branch.NewManager(
branch.WithRepoRoot(cfg.RepoRootDir),
branch.WithRepoRemote(c.String(repoRemoteFlag.Name)),
branch.WithMainBranch(c.String(mainBranchFlag.Name)),
branch.WithDevTagIdentifier(c.String(devTagSuffixFlag.Name)),
branch.WithReleaseBranchPrefix(c.String(releaseBranchPrefixFlag.Name)),
branch.WithValidate(!c.Bool(skipValidationFlag.Name)),
branch.WithPublish(c.Bool(publishBranchFlag.Name)))
return m.CutReleaseBranch()
},
},
}
}
// Cut a new operator release branch
{
Name: "cut-operator",
Usage: fmt.Sprintf("Cut a new operator release branch from %s", utils.DefaultBranch),
Flags: append(operatorGitFlags,
operatorBaseBranchFlag,
operatorReleaseBranchPrefixFlag,
operatorDevTagSuffixFlag,
newBranchFlag,
publishBranchFlag,
skipValidationFlag,
),
Action: func(c *cli.Context) error {
configureLogging("cut-operator-branch.log")

// cutOperatorBranchCommand is a subcommand to cut a new operator release branch.
func cutOperatorBranchCommand(cfg *Config) *cli.Command {
operatorBaseBranchFlag := operatorBranchFlag
operatorBaseBranchFlag.Usage = "The base branch to cut the Tigera operator release branch from"
operatorBaseBranchFlag.EnvVars = []string{"OPERATOR_BRANCH_BASE"}

return &cli.Command{
Name: "cut-operator",
Usage: fmt.Sprintf("Cut a new operator release branch from %s", utils.DefaultBranch),
Flags: append(operatorGitFlags,
operatorBaseBranchFlag, operatorReleaseBranchPrefixFlag, operatorDevTagSuffixFlag,
newBranchFlag, publishBranchFlag, skipValidationFlag,
),
Action: func(c *cli.Context) error {
configureLogging("cut-operator-branch.log")
// Warn if the new branch is not the default base branch
if c.String(newBranchFlag.Name) != newBranchFlag.Value {
logrus.Warnf("The new branch will be created from %s which is not the default branch %s", c.String(newBranchFlag.Name), newBranchFlag.Value)
}

// Warn if the new branch is not the default base branch
if c.String(newBranchFlag.Name) != newBranchFlag.Value {
logrus.Warnf("The new branch will be created from %s which is not the default branch %s", c.String(newBranchFlag.Name), newBranchFlag.Value)
}
// Clone the operator repository
operatorDir := filepath.Join(cfg.TmpDir, operator.DefaultRepoName)
if err := operator.Clone(c.String(operatorOrgFlag.Name), c.String(operatorRepoFlag.Name), c.String(operatorBaseBranchFlag.Name), operatorDir); err != nil {
return err
}

// Create operator manager
m := operator.NewManager(
operator.WithOperatorDirectory(filepath.Join(cfg.TmpDir, operator.DefaultRepoName)),
operator.WithRepoRemote(c.String(operatorRepoRemoteFlag.Name)),
operator.WithGithubOrg(c.String(operatorOrgFlag.Name)),
operator.WithRepoName(c.String(operatorRepoFlag.Name)),
operator.WithBranch(operatorBaseBranchFlag.Name),
operator.WithDevTagIdentifier(operatorDevTagSuffixFlag.Name),
operator.WithReleaseBranchPrefix(c.String(operatorReleaseBranchPrefixFlag.Name)),
operator.WithValidate(!c.Bool(skipValidationFlag.Name)),
operator.WithPublish(c.Bool(publishBranchFlag.Name)),
)
// Create operator manager
m := operator.NewManager(
operator.WithOperatorDirectory(operatorDir),
operator.WithRepoRemote(c.String(operatorRepoRemoteFlag.Name)),
operator.WithGithubOrg(c.String(operatorOrgFlag.Name)),
operator.WithRepoName(c.String(operatorRepoFlag.Name)),
operator.WithBranch(operatorBaseBranchFlag.Name),
operator.WithDevTagIdentifier(operatorDevTagSuffixFlag.Name),
operator.WithReleaseBranchPrefix(c.String(operatorReleaseBranchPrefixFlag.Name)),
operator.WithValidate(!c.Bool(skipValidationFlag.Name)),
operator.WithPublish(c.Bool(publishBranchFlag.Name)),
)

return m.CutBranch(c.String(newBranchFlag.Name))
return m.CutBranch(c.String(newBranchFlag.Name))
},
},
}
}
56 changes: 37 additions & 19 deletions release/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/projectcalico/calico/release/pkg/manager/operator"
)

// globalFlags are flags that are used across all commands
var globalFlags = append([]cli.Flag{debugFlag}, append(ciFlags, slackFlags...)...)

// debugFlag is a flag used to enable verbose log output
Expand All @@ -40,10 +39,13 @@ var debugFlag = &cli.BoolFlag{
// Product repository flags are flags used to interact with the product repository
var (
gitFlags = []cli.Flag{orgFlag, repoFlag, repoRemoteFlag}
productFlags = append(gitFlags, []cli.Flag{
productFlags = []cli.Flag{
orgFlag,
repoFlag,
repoRemoteFlag,
releaseBranchPrefixFlag,
devTagSuffixFlag,
}...)
}

// Git flags for interacting with the git repository
orgFlag = &cli.StringFlag{
Expand Down Expand Up @@ -92,6 +94,11 @@ var (
Name: "branch-stream",
Usage: fmt.Sprintf("The new major and minor versions for the branch to create e.g. vX.Y to create a %s-vX.Y branch", releaseBranchPrefixFlag.Value),
}
baseBranchFlag = &cli.StringFlag{
Name: "base-branch",
Usage: "The base branch to cut the release branch from",
EnvVars: []string{"RELEASE_BRANCH_BASE"},
}
)

// Validation flags are flags used to control validation
Expand All @@ -109,24 +116,20 @@ var (
registryFlag = &cli.StringSliceFlag{
Name: "registry",
Usage: "Override default registries for the release. Repeat for multiple registries.",
EnvVars: []string{"REGISTRIES"}, // DEV_REGISITRIES is already used by the build system.
EnvVars: []string{"REGISTRIES"}, // avoid DEV_REGISTRIES as it is already used by the build system (lib.Makefile).
Value: cli.NewStringSlice(),
}

amd64Arch = "amd64"
arm64Arch = "arm64"
ppc64leArch = "ppc64le"
s390xArch = "s390x"
validArches = []string{amd64Arch, arm64Arch, ppc64leArch, s390xArch}
archOptions = []string{"amd64", "arm64", "ppc64le", "s390x"}
archFlag = &cli.StringSliceFlag{
Name: "architecture",
Aliases: []string{"arch"},
Usage: "The architecture to use for the release. Repeat for multiple architectures.",
EnvVars: []string{"ARCHS"}, // ARCHES is already used by the build system.
Value: cli.NewStringSlice(validArches...),
EnvVars: []string{"ARCHS"}, // avoid ARCHES as it is already used by the build system (lib.Makefile).
Value: cli.NewStringSlice(archOptions...),
Action: func(c *cli.Context, values []string) error {
for _, arch := range values {
if !utils.Contains(validArches, arch) {
if !utils.Contains(archOptions, arch) {
return fmt.Errorf("invalid architecture %s", arch)
}
}
Expand All @@ -137,27 +140,38 @@ var (
buildImagesFlag = &cli.BoolFlag{
Name: "build-images",
Usage: "Build container images from the local code",
EnvVars: []string{"BUILD_CONTAINER_IMAGES"}, // BUILD_IMAGES is already used by the build system.
EnvVars: []string{"BUILD_CONTAINER_IMAGES"}, // avoid BUILD_IMAGES as it is already used by the build system (lib.Makefile).
Value: true,
}
buildHashreleaseImageFlag = &cli.BoolFlag{
Name: buildImagesFlag.Name,
Usage: buildImagesFlag.Usage,
EnvVars: buildImagesFlag.EnvVars,
Value: false,
}

publishImagesFlag = &cli.BoolFlag{
Name: "publish-images",
Usage: "Publish images to the registry",
EnvVars: []string{"PUBLISH_IMAGES"},
Value: true,
}
publishHashreleaseImageFlag = &cli.BoolFlag{
Name: publishImagesFlag.Name,
Usage: publishImagesFlag.Usage,
EnvVars: publishImagesFlag.EnvVars,
Value: false,
}
)

// Operator flags are flags used to interact with Tigera operator repository
var (
operatorGitFlags = []cli.Flag{
operatorGitFlags = []cli.Flag{operatorRepoRemoteFlag, operatorOrgFlag, operatorRepoFlag}
operatorBuildFlags = []cli.Flag{
operatorRepoRemoteFlag, operatorOrgFlag, operatorRepoFlag,
}
operatorBuildFlags = append(operatorGitFlags, []cli.Flag{
operatorBranchFlag, operatorReleaseBranchPrefixFlag, operatorDevTagSuffixFlag,
operatorRegistryFlag, operatorImageFlag,
}...)
}

// Operator git flags
operatorOrgFlag = &cli.StringFlag{
Expand Down Expand Up @@ -198,6 +212,11 @@ var (
EnvVars: []string{"OPERATOR_DEV_TAG_SUFFIX"},
Value: operator.DefaultDevTagSuffix,
}
operatorBaseBranchFlag = &cli.StringFlag{
Name: operatorBranchFlag.Name,
Usage: "The base branch to cut the Tigera operator release branch from",
EnvVars: []string{"OPERATOR_BRANCH_BASE"},
}

// Container image flags
operatorRegistryFlag = &cli.StringFlag{
Expand Down Expand Up @@ -395,8 +414,7 @@ var (
Usage: "The maximum number of hashreleases to keep on the hashrelease server",
Value: hashreleaseserver.DefaultMax,
}
hashreleasePublishFlags = []cli.Flag{publishHashreleaseFlag, latestFlag}
publishHashreleaseFlag = &cli.BoolFlag{
publishHashreleaseFlag = &cli.BoolFlag{
Name: "publish-to-hashrelease-server",
Usage: "Publish the hashrelease to the hashrelease server",
Value: true,
Expand Down
Loading

0 comments on commit 7d53965

Please sign in to comment.