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

dry run and tagging functionality #341

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 8 additions & 6 deletions cmd/release/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,37 @@ 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
},
}

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
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/release/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 80 additions & 7 deletions cmd/release/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ package cmd

import (
"context"
"errors"
"fmt"
"os"
"time"

"github.com/rancher/ecm-distro-tools/release/rke2"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/spf13/cobra"
)

var (
alpineVersion *string
alpineVersion *string
releaseVersion *string
rcVersion *string
rpmVersion *int
)

// tagCmd represents the tag command.
Expand Down Expand Up @@ -40,19 +45,80 @@ 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 {
return errors.New("invalid release version")
}

ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

switch args[0] {
case "image-build-base":
if err := rke2.ImageBuildBaseRelease(ctx, client, *alpineVersion, *dryRun); err != nil {
return err
}
case "image-build-kubernetes":
if err := rke2.ImageBuildBaseRelease(ctx, client, *alpineVersion, false); err != nil {
fmt.Println(err)
os.Exit(1)
now := time.Now().UTC().Format("20060201")
suffix := "+rke2" + *releaseVersion + "-build" + now

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 {
return err
}

fmt.Println("tag " + version + suffix + " created successfully")
}
}
case "rke2":
//
case "rpm":
if len(args) == 1 {
return errors.New("invalid rpm tag. expected {testinglatest|stable}")
}

fmt.Println("Successfully tagged")
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.Print("(dry-run)\n\nTagging github.com/rancher/rke2-packaging:\n\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 {
return err
}
}
}
default:
return errors.New("unrecognized resource")
}

return nil
},
}

Expand All @@ -62,6 +128,13 @@ func init() {
tagCmd.AddCommand(k3sTagSubCmd)
tagCmd.AddCommand(rke2TagSubCmd)

dryRun = tagCmd.PersistentFlags().BoolP("dry-run", "d", false, "Dry run")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this persistent flag to root.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had given that some thought but not all commands will have/need 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
Expand All @@ -70,5 +143,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")

}