Skip to content

Commit

Permalink
[release tool] remove config package (projectcalico#9578)
Browse files Browse the repository at this point in the history
* switch to flags instead of using config package

* clean ups

- minimize hardcoded strings
- reduce info logs
- created shared.go for fns used across commands

* trim fat and address review feedback

* keep repoRoot as internal config
  • Loading branch information
radTuti committed Dec 31, 2024
1 parent 4088f2f commit 82d748d
Show file tree
Hide file tree
Showing 25 changed files with 963 additions and 546 deletions.
2 changes: 1 addition & 1 deletion .semaphore/release/hashrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ blocks:
jobs:
- name: Build and publish hashrelease
commands:
- if [[ ${SEMAPHORE_WORKFLOW_TRIGGERED_BY_SCHEDULE} == "true" ]]; then export BUILD_CONTAINER_IMAGES=true; export SKIP_PUBLISH_IMAGES=false; fi
- if [[ ${SEMAPHORE_WORKFLOW_TRIGGERED_BY_SCHEDULE} == "true" ]]; then export BUILD_CONTAINER_IMAGES=true; export PUBLISH_IMAGES=true; fi
- make hashrelease
prologue:
commands:
Expand Down
80 changes: 47 additions & 33 deletions release/cmd/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ package main

import (
"fmt"
"path/filepath"

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

"github.com/projectcalico/calico/release/internal/config"
"github.com/projectcalico/calico/release/internal/utils"
"github.com/projectcalico/calico/release/pkg/manager/branch"
"github.com/projectcalico/calico/release/pkg/manager/operator"
)

// The branch command suite is used to manage branches.
func branchCommand(cfg *config.Config) *cli.Command {
func branchCommand(cfg *Config) *cli.Command {
return &cli.Command{
Name: "branch",
Aliases: []string{"br"},
Expand All @@ -36,62 +36,76 @@ func branchCommand(cfg *config.Config) *cli.Command {
}
}

func branchSubCommands(cfg *config.Config) []*cli.Command {
func branchSubCommands(cfg *Config) []*cli.Command {
return []*cli.Command{
// Cut a new release branch
{
Name: "cut",
Usage: fmt.Sprintf("Cut a new release branch from %s", utils.DefaultBranch),
Flags: []cli.Flag{
&cli.BoolFlag{Name: skipValidationFlag, Usage: "Skip release branch cut validations", Value: false},
&cli.BoolFlag{Name: publishBranchFlag, Usage: "Push branch and tag to git. If false, all changes are local.", Value: false},
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(cfg.GitRemote),
branch.WithMainBranch(utils.DefaultBranch),
branch.WithDevTagIdentifier(cfg.DevTagSuffix),
branch.WithReleaseBranchPrefix(cfg.RepoReleaseBranchPrefix),
branch.WithValidate(!c.Bool(skipValidationFlag)),
branch.WithPublish(c.Bool(publishBranchFlag)))

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: []cli.Flag{
&cli.StringFlag{Name: operatorOrgFlag, Usage: "Operator git organization", EnvVars: []string{"OPERATOR_GIT_ORGANIZATION"}, Value: config.OperatorDefaultOrg},
&cli.StringFlag{Name: operatorRepoFlag, Usage: "Operator git repository", EnvVars: []string{"OPERATOR_GIT_REPO"}, Value: config.OperatorDefaultRepo},
&cli.BoolFlag{Name: skipValidationFlag, Usage: "Skip release branch cut validations", Value: false},
&cli.BoolFlag{Name: publishBranchFlag, Usage: "Push branch and tag to git. If false, all changes are local.", Value: false},
&cli.StringFlag{Name: sourceBranchFlag, Usage: "The branch to cut the operator release from", Value: utils.DefaultBranch},
&cli.StringFlag{Name: newBranchFlag, Usage: fmt.Sprintf("The new version for the branch to create i.e. vX.Y to create a %s-vX.Y branch", cfg.Operator.RepoReleaseBranchPrefix), Value: ""},
},
Flags: append(operatorGitFlags,
operatorBaseBranchFlag,
operatorReleaseBranchPrefixFlag,
operatorDevTagSuffixFlag,
newBranchFlag,
publishBranchFlag,
skipValidationFlag,
),
Action: func(c *cli.Context) error {
configureLogging("cut-operator-branch.log")
if c.String(newBranchFlag) == "" {
logrus.Warn("No branch version specified, will cut branch based on latest dev tag")

// 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
if err := utils.Clone(fmt.Sprintf("git@github.com:%s/%s.git", c.String(operatorOrgFlag), c.String(operatorRepoFlag)), cfg.Operator.Branch, cfg.Operator.Dir); err != nil {
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(cfg.Operator.Dir),
operator.WithRepoRemote(cfg.Operator.GitRemote),
operator.WithGithubOrg(c.String(operatorOrgFlag)),
operator.WithRepoName(c.String(operatorRepoFlag)),
operator.WithBranch(utils.DefaultBranch),
operator.WithDevTagIdentifier(cfg.Operator.DevTagSuffix),
operator.WithReleaseBranchPrefix(cfg.Operator.RepoReleaseBranchPrefix),
operator.WithValidate(!c.Bool(skipValidationFlag)),
operator.WithPublish(c.Bool(publishBranchFlag)),
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))

return m.CutBranch(c.String(newBranchFlag.Name))
},
},
}
Expand Down
Loading

0 comments on commit 82d748d

Please sign in to comment.