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

Refactor tag rancher command #482

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions cmd/release/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ type tagRKE2CmdFlags struct {
}

var (
tagRKE2Flags tagRKE2CmdFlags
tagRKE2Flags tagRKE2CmdFlags
tagRancherSkipStatusCheck bool
)

// tagCmd represents the tag command.
Expand Down Expand Up @@ -140,11 +141,11 @@ var rke2TagSubCmd = &cobra.Command{
}

var rancherTagSubCmd = &cobra.Command{
Use: "rancher [ga, rc, debug, alpha] [version]",
Use: "rancher [ga, rc, alpha] [version]",
Short: "Tag Rancher releases",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.New("expected at least two arguments: [ga,rc,debug,alpha] [version]")
return errors.New("expected at least two arguments: [ga,rc,alpha] [version]")
}
releaseType := args[0]
preRelease, err := releaseTypePreRelease(releaseType)
Expand All @@ -161,12 +162,23 @@ var rancherTagSubCmd = &cobra.Command{
ghClient := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

opts := &repository.CreateReleaseOpts{
Tag: tag,
Repo: "rancher",
Owner: rancherRelease.RancherRepoOwner,
Branch: rancherRelease.ReleaseBranch,
Tag: tag,
Repo: "rancher",
Owner: rancherRelease.RancherRepoOwner,
Branch: rancherRelease.ReleaseBranch,
ReleaseNotes: "",
}
fmt.Printf("creating release options: %+v\n", opts)
if dryRun {
tashima42 marked this conversation as resolved.
Show resolved Hide resolved
fmt.Println("dry run, skipping creating release")
return nil
}
return rancher.CreateRelease(ctx, ghClient, &rancherRelease, opts, preRelease, releaseType)
releaseURL, err := rancher.CreateRelease(ctx, ghClient, &rancherRelease, opts, preRelease, tagRancherSkipStatusCheck, releaseType)
if err != nil {
return err
}
fmt.Println("created release: " + releaseURL)
return nil
},
}

Expand Down Expand Up @@ -217,16 +229,19 @@ func init() {
tagRKE2Flags.ReleaseVersion = rke2TagSubCmd.Flags().StringP("release-version", "r", "r1", "Release version")
tagRKE2Flags.RCVersion = rke2TagSubCmd.Flags().String("rc", "", "RC version")
tagRKE2Flags.RPMVersion = rke2TagSubCmd.Flags().Int("rpm-version", 0, "RPM version")

// rancher
rancherTagSubCmd.Flags().BoolVarP(&tagRancherSkipStatusCheck, "skip-status-check", "s", false, "skip checking if CI is passing when creating a tag")
}

func releaseTypePreRelease(releaseType string) (bool, error) {
if releaseType == "rc" || releaseType == "debug" || releaseType == "alpha" {
if releaseType == "rc" || releaseType == "alpha" {
return true, nil
}

if releaseType == "ga" {
return false, nil
}

return false, errors.New("release type must be either 'ga', 'debug', 'alpha' or 'rc', instead got: " + releaseType)
return false, errors.New("release type must be either 'ga', 'alpha' or 'rc', instead got: " + releaseType)
}
23 changes: 4 additions & 19 deletions cmd/release/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ type K3sRelease struct {

// RancherRelease
type RancherRelease struct {
ReleaseBranch string `json:"release_branch" validate:"required"`
RancherRepoOwner string `json:"rancher_repo_owner" validate:"required"`
IssueNumber string `json:"issue_number" validate:"number"`
BaseRegistry string `json:"base_registry" validate:"required,hostname"`
Registry string `json:"registry" validate:"required,hostname"`
PrimeArtifactsBucket string `json:"prime_artifacts_bucket" validate:"required"`
DryRun bool `json:"dry_run"`
SkipStatusCheck bool `json:"skip_status_check"`
ReleaseBranch string `json:"release_branch" validate:"required"`
RancherRepoOwner string `json:"rancher_repo_owner" validate:"required"`
}

// RKE2
Expand Down Expand Up @@ -163,14 +157,8 @@ func ExampleConfig() (string, error) {
Rancher: &Rancher{
Versions: map[string]RancherRelease{
"v2.x.y": {
ReleaseBranch: "release/v2.x",
DryRun: false,
SkipStatusCheck: false,
RancherRepoOwner: "rancher",
IssueNumber: "1234",
BaseRegistry: "stgregistry.suse.com",
Registry: "registry.rancher.com",
PrimeArtifactsBucket: "prime-artifacts",
ReleaseBranch: "release/v2.x",
RancherRepoOwner: "rancher",
},
},
},
Expand Down Expand Up @@ -234,9 +222,6 @@ K3s {{ range $k3sVersion, $k3sValue := .K3s.Versions }}
Rancher {{ range $rancherVersion, $rancherValue := .Rancher.Versions }}
{{ $rancherVersion }}:
Release Branch: {{ $rancherValue.ReleaseBranch }}
Dry Run: {{ $rancherValue.DryRun }}
Skip Status Check: {{ $rancherValue.SkipStatusCheck }}
Issue Number: {{ $rancherValue.IssueNumber }}
Rancher Repo Owner: {{ $rancherValue.RancherRepoOwner }}{{ end }}

RKE2{{ range .RKE2.Versions }}
Expand Down
31 changes: 31 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,52 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.5 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.30.5 // indirect
github.com/aws/smithy-go v1.20.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.4.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.9.1 // indirect
github.com/prometheus/procfs v0.0.8 // indirect
github.com/rancher/norman v0.0.0-20200520181341-ab75acb55410 // indirect
github.com/rancher/rancher v2.2.13+incompatible // indirect
github.com/rancher/types v0.0.0-20220328215343-4370ff10ecd5 // indirect
github.com/rancher/wrangler v0.5.4-0.20200520040055-b8d49179cfc8 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
golang.org/x/term v0.23.0 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.18.0 // indirect
k8s.io/apimachinery v0.18.0 // indirect
k8s.io/apiserver v0.18.0 // indirect
k8s.io/client-go v12.0.0+incompatible // indirect
k8s.io/klog v1.0.0 // indirect
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89 // indirect
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

require (
Expand Down
Loading
Loading