From cbb2e7d575b4a39e837c4b813f5b9158ddc6ac7a Mon Sep 17 00:00:00 2001 From: Brian Downs Date: Tue, 16 Jan 2024 11:04:07 -0700 Subject: [PATCH 1/6] remove binary Signed-off-by: Brian Downs --- cmd/release/cmd/root.go | 1 + cmd/release/cmd/tag.go | 86 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/cmd/release/cmd/root.go b/cmd/release/cmd/root.go index dd9dcc47..f6083d34 100644 --- a/cmd/release/cmd/root.go +++ b/cmd/release/cmd/root.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" ) +var dryRun *bool var rootConfig *config.Config // rootCmd represents the base command when called without any subcommands diff --git a/cmd/release/cmd/tag.go b/cmd/release/cmd/tag.go index 58189fa1..4c10f8f6 100644 --- a/cmd/release/cmd/tag.go +++ b/cmd/release/cmd/tag.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "time" "github.com/rancher/ecm-distro-tools/release/rke2" "github.com/rancher/ecm-distro-tools/repository" @@ -11,7 +12,10 @@ import ( ) var ( - alpineVersion *string + alpineVersion *string + releaseVersion *string + rcVersion *string + rpmVersion *int ) // tagCmd represents the tag command. @@ -41,17 +45,82 @@ var rke2TagSubCmd = &cobra.Command{ Short: "", Long: ``, Run: func(cmd *cobra.Command, args []string) { + if len(*releaseVersion) != 2 { + fmt.Println("error: invalid release version") + os.Exit(1) + } + ctx := context.Background() client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken) switch args[0] { - case "image-build-kubernetes": - if err := rke2.ImageBuildBaseRelease(ctx, client, *alpineVersion, false); err != nil { + case "image-build-base": + if err := rke2.ImageBuildBaseRelease(ctx, client, *alpineVersion, *dryRun); err != nil { fmt.Println(err) os.Exit(1) } + case "image-build-kubernetes": + now := time.Now().UTC().Format("20060201") + suffix := "+rke2" + *releaseVersion + "-build" + now - fmt.Println("Successfully tagged") + if *dryRun { + fmt.Println("dry-run:") + for _, version := range rootConfig.RKE2.Versions { + fmt.Println("\t" + version + suffix) + } + } else { + for _, version := range rootConfig.RKE2.Versions { + cro := repository.CreateReleaseOpts{ + Owner: "rancher", + Repo: "image-build-kubernetes", + Branch: "master", + Name: version + suffix, + Prerelease: false, + } + if _, err := repository.CreateRelease(ctx, client, &cro); err != nil { + fmt.Println(err) + os.Exit(1) + } + + fmt.Println("tag " + version + suffix + " created successfully") + } + } + case "rke2": + // + case "rpm": + if len(args) == 1 { + fmt.Println("error: invalid rpm tag. expected {testinglatest|stable}") + os.Exit(1) + } + + rpmTag := fmt.Sprintf("+rke2%s.%s.%d", *releaseVersion, args[1], *rpmVersion) + if *rcVersion != "" { + rpmTag = fmt.Sprintf("+rke2%s-rc%s.%s.%d", *releaseVersion, *rcVersion, args[1], *rpmVersion) + } + + if *dryRun { + fmt.Println("(dry-run)\n\nTagging github.com/rancher/rke2-packaging: \n") + for _, version := range rootConfig.RKE2.Versions { + fmt.Println("\t" + version + rpmTag) + } + } else { + for _, version := range rootConfig.RKE2.Versions { + cro := repository.CreateReleaseOpts{ + Owner: "rancher", + Repo: "rke2-packaging", + Branch: "master", + Name: version + rpmTag, + Prerelease: false, + } + if _, err := repository.CreateRelease(ctx, client, &cro); err != nil { + fmt.Println(err) + os.Exit(1) + } + } + } + default: + fmt.Println("error: unrecognized resource") + os.Exit(1) } }, } @@ -62,6 +131,13 @@ func init() { tagCmd.AddCommand(k3sTagSubCmd) tagCmd.AddCommand(rke2TagSubCmd) + dryRun = tagCmd.PersistentFlags().BoolP("dry-run", "d", false, "Dry run") + + alpineVersion = rke2TagSubCmd.Flags().StringP("alpine-version", "a", "", "Alpine version") + releaseVersion = rke2TagSubCmd.Flags().StringP("release-version", "r", "r1", "Release version") + rcVersion = rke2TagSubCmd.Flags().String("rc", "", "RC version") + rpmVersion = rke2TagSubCmd.Flags().Int("rpm-version", 0, "RPM version") + // Here you will define your flags and configuration settings. // Cobra supports Persistent Flags which will work for this command @@ -70,5 +146,5 @@ func init() { // Cobra supports local flags which will only run when this command // is called directly, e.g.: - tagCmd.Flags().StringP("alpine-version", "a", "", "Alpine version") + } From 44434233a978b0304934917fedc95db688861428 Mon Sep 17 00:00:00 2001 From: Brian Downs Date: Tue, 16 Jan 2024 10:19:58 -0700 Subject: [PATCH 2/6] update tag errors Signed-off-by: Brian Downs --- cmd/release/cmd/tag.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/cmd/release/cmd/tag.go b/cmd/release/cmd/tag.go index 4c10f8f6..2836ef69 100644 --- a/cmd/release/cmd/tag.go +++ b/cmd/release/cmd/tag.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "errors" "fmt" "os" "time" @@ -44,10 +45,9 @@ var rke2TagSubCmd = &cobra.Command{ Use: "rke2", Short: "", Long: ``, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { if len(*releaseVersion) != 2 { - fmt.Println("error: invalid release version") - os.Exit(1) + return errors.New("invalid release version") } ctx := context.Background() @@ -56,8 +56,7 @@ var rke2TagSubCmd = &cobra.Command{ switch args[0] { case "image-build-base": if err := rke2.ImageBuildBaseRelease(ctx, client, *alpineVersion, *dryRun); err != nil { - fmt.Println(err) - os.Exit(1) + return err } case "image-build-kubernetes": now := time.Now().UTC().Format("20060201") @@ -78,8 +77,7 @@ var rke2TagSubCmd = &cobra.Command{ Prerelease: false, } if _, err := repository.CreateRelease(ctx, client, &cro); err != nil { - fmt.Println(err) - os.Exit(1) + return err } fmt.Println("tag " + version + suffix + " created successfully") @@ -89,8 +87,7 @@ var rke2TagSubCmd = &cobra.Command{ // case "rpm": if len(args) == 1 { - fmt.Println("error: invalid rpm tag. expected {testinglatest|stable}") - os.Exit(1) + return errors.New("invalid rpm tag. expected {testinglatest|stable}") } rpmTag := fmt.Sprintf("+rke2%s.%s.%d", *releaseVersion, args[1], *rpmVersion) @@ -113,15 +110,15 @@ var rke2TagSubCmd = &cobra.Command{ Prerelease: false, } if _, err := repository.CreateRelease(ctx, client, &cro); err != nil { - fmt.Println(err) - os.Exit(1) + return err } } } default: - fmt.Println("error: unrecognized resource") - os.Exit(1) + return errors.New("unrecognized resource") } + + return nil }, } From 81164eb94464ead1eb06fee85fb30c3d2581f1f9 Mon Sep 17 00:00:00 2001 From: Brian Downs Date: Tue, 16 Jan 2024 10:21:07 -0700 Subject: [PATCH 3/6] update generate errors Signed-off-by: Brian Downs --- cmd/release/cmd/generate.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/release/cmd/generate.go b/cmd/release/cmd/generate.go index 185cc03f..dcc6286d 100644 --- a/cmd/release/cmd/generate.go +++ b/cmd/release/cmd/generate.go @@ -32,17 +32,18 @@ var k3sGenerateSubCmd = &cobra.Command{ Use: "k3s", Short: "", Long: ``, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken) notes, err := release.GenReleaseNotes(ctx, "k3s-io", "k3s", *milestone, *prevMilestone, client) if err != nil { - fmt.Println(err) - os.Exit(1) + return err } fmt.Print(notes.String()) + + return nil }, } @@ -50,17 +51,18 @@ var rke2GenerateSubCmd = &cobra.Command{ Use: "rke2", Short: "", Long: ``, - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) error { ctx := context.Background() client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken) notes, err := release.GenReleaseNotes(ctx, "rancher", "rke2", *milestone, *prevMilestone, client) if err != nil { - fmt.Println(err) - os.Exit(1) + return err } fmt.Print(notes.String()) + + return nil }, } From a6934d4a62490d4a567c34804f3a3365ec07857d Mon Sep 17 00:00:00 2001 From: Brian Downs Date: Tue, 16 Jan 2024 10:37:30 -0700 Subject: [PATCH 4/6] make go do what I want Signed-off-by: Brian Downs --- cmd/release/cmd/tag.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/release/cmd/tag.go b/cmd/release/cmd/tag.go index 2836ef69..a7dbe796 100644 --- a/cmd/release/cmd/tag.go +++ b/cmd/release/cmd/tag.go @@ -96,7 +96,7 @@ var rke2TagSubCmd = &cobra.Command{ } if *dryRun { - fmt.Println("(dry-run)\n\nTagging github.com/rancher/rke2-packaging: \n") + fmt.Print("(dry-run)\n\nTagging github.com/rancher/rke2-packaging:\n\n") for _, version := range rootConfig.RKE2.Versions { fmt.Println("\t" + version + rpmTag) } From bef2bd5d24d3dc1d3b60b6324d979ad2c04c9575 Mon Sep 17 00:00:00 2001 From: Brian Downs Date: Tue, 16 Jan 2024 13:59:23 -0700 Subject: [PATCH 5/6] fix to be idiomatic Signed-off-by: Brian Downs --- cmd/release/cmd/root.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/release/cmd/root.go b/cmd/release/cmd/root.go index f6083d34..f601c118 100644 --- a/cmd/release/cmd/root.go +++ b/cmd/release/cmd/root.go @@ -22,8 +22,7 @@ var rootCmd = &cobra.Command{ // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { - err := rootCmd.Execute() - if err != nil { + if err := rootCmd.Execute(); err != nil { os.Exit(1) } } From 1958374d10a957fecc220c50ea1d06b90105e419 Mon Sep 17 00:00:00 2001 From: Brian Downs Date: Tue, 16 Jan 2024 14:20:13 -0700 Subject: [PATCH 6/6] comment Signed-off-by: Brian Downs --- cmd/release/cmd/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/release/cmd/root.go b/cmd/release/cmd/root.go index f601c118..4651bab4 100644 --- a/cmd/release/cmd/root.go +++ b/cmd/release/cmd/root.go @@ -23,6 +23,7 @@ var rootCmd = &cobra.Command{ // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { if err := rootCmd.Execute(); err != nil { + fmt.Println("error: " + err.Error()) os.Exit(1) } }