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

[feature] Rancher UI dashboard commands #474

Merged
merged 17 commits into from
Oct 16, 2024
77 changes: 77 additions & 0 deletions cmd/release/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var (
k3sPrevMilestone string
k3sMilestone string

dashboardPrevMilestone string
dashboardMilestone string

concurrencyLimit int
imagesListURL string
ignoreImages []string
Expand Down Expand Up @@ -172,6 +175,52 @@ var rancherGenerateImagesSyncConfigSubCmd = &cobra.Command{
},
}

var uiGenerateSubCmd = &cobra.Command{
Use: "ui",
Short: "Generate ui related artifacts",
}

var uiGenerateReleaseNotesSubCmd = &cobra.Command{
Use: "release-notes",
Short: "Generate ui release notes",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

notes, err := release.GenReleaseNotes(ctx, "rancher", "ui", dashboardMilestone, dashboardPrevMilestone, client)
if err != nil {
return err
}

fmt.Print(notes.String())

return nil
},
}

var dashboardGenerateSubCmd = &cobra.Command{
Use: "dashboard",
Short: "Generate dashboard related artifacts",
}

var dashboardGenerateReleaseNotesSubCmd = &cobra.Command{
Use: "release-notes",
Short: "Generate dashboard release notes",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

notes, err := release.GenReleaseNotes(ctx, "rancher", "dashboard", dashboardMilestone, dashboardPrevMilestone, client)
if err != nil {
return err
}

fmt.Print(notes.String())

return nil
},
}

func init() {
rootCmd.AddCommand(generateCmd)

Expand All @@ -182,10 +231,14 @@ func init() {
rancherGenerateSubCmd.AddCommand(rancherGenerateMissingImagesListSubCmd)
rancherGenerateSubCmd.AddCommand(rancherGenerateDockerImagesDigestsSubCmd)
rancherGenerateSubCmd.AddCommand(rancherGenerateImagesSyncConfigSubCmd)
uiGenerateSubCmd.AddCommand(uiGenerateReleaseNotesSubCmd)
dashboardGenerateSubCmd.AddCommand(dashboardGenerateReleaseNotesSubCmd)

generateCmd.AddCommand(k3sGenerateSubCmd)
generateCmd.AddCommand(rke2GenerateSubCmd)
generateCmd.AddCommand(rancherGenerateSubCmd)
generateCmd.AddCommand(uiGenerateSubCmd)
generateCmd.AddCommand(dashboardGenerateSubCmd)

// k3s release notes
k3sGenerateReleaseNotesSubCmd.Flags().StringVarP(&k3sPrevMilestone, "prev-milestone", "p", "", "Previous Milestone")
Expand All @@ -211,6 +264,30 @@ func init() {
os.Exit(1)
}

// ui release notes
uiGenerateReleaseNotesSubCmd.Flags().StringVarP(&dashboardPrevMilestone, "prev-milestone", "p", "", "Previous Milestone")
uiGenerateReleaseNotesSubCmd.Flags().StringVarP(&dashboardMilestone, "milestone", "m", "", "Milestone")
if err := uiGenerateReleaseNotesSubCmd.MarkFlagRequired("prev-milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err := uiGenerateReleaseNotesSubCmd.MarkFlagRequired("milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

// dashboard release notes
dashboardGenerateReleaseNotesSubCmd.Flags().StringVarP(&dashboardPrevMilestone, "prev-milestone", "p", "", "Previous Milestone")
dashboardGenerateReleaseNotesSubCmd.Flags().StringVarP(&dashboardMilestone, "milestone", "m", "", "Milestone")
if err := dashboardGenerateReleaseNotesSubCmd.MarkFlagRequired("prev-milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err := dashboardGenerateReleaseNotesSubCmd.MarkFlagRequired("milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

// rancher artifacts-index
rancherGenerateArtifactsIndexSubCmd.Flags().StringSliceVarP(&rancherArtifactsIndexIgnoreVersions, "ignore-versions", "i", []string{}, "Versions to ignore on the index")
rancherGenerateArtifactsIndexSubCmd.Flags().StringVarP(&rancherArtifactsIndexWriteToPath, "write-path", "w", "", "Write To Path")
Expand Down
96 changes: 96 additions & 0 deletions cmd/release/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (
"fmt"
"time"

"github.com/Masterminds/semver/v3"
"github.com/rancher/ecm-distro-tools/cmd/release/config"
"github.com/rancher/ecm-distro-tools/release/dashboard"
"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/rancher/ecm-distro-tools/release/rke2"
"github.com/rancher/ecm-distro-tools/release/ui"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -146,11 +150,13 @@ var rancherTagSubCmd = &cobra.Command{
if len(args) < 2 {
return errors.New("expected at least two arguments: [ga,rc,debug,alpha] [version]")
}

releaseType := args[0]
preRelease, err := releaseTypePreRelease(releaseType)
if err != nil {
return err
}

tag := args[1]
rancherRelease, found := rootConfig.Rancher.Versions[tag]
if !found {
Expand Down Expand Up @@ -204,13 +210,103 @@ var systemAgentInstallerK3sTagSubCmd = &cobra.Command{
},
}

var uiTagSubCmd = &cobra.Command{
Use: "ui [ga,rc] [version]",
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved
Short: "Tag ui releases",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.New("expected at least two arguments: [ga,rc] [version]")
}

releaseType := args[0]

rc, err := releaseTypePreRelease(releaseType)
if err != nil {
return err
}

tag := args[1]
briandowns marked this conversation as resolved.
Show resolved Hide resolved
_, err = semver.NewVersion(tag)
if err != nil {
return err
}

uiRelease, found := rootConfig.UI.Versions[tag]
if !found {
return errors.New("verify your config file, version not found: " + tag)
}

ctx := context.Background()
ghClient := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)
opts := &repository.CreateReleaseOpts{
Tag: tag,
Repo: "ui",
Owner: uiRelease.UIRepoOwner,
Branch: uiRelease.ReleaseBranch,
}

return ui.CreateRelease(ctx, ghClient, &uiRelease, opts, rc, releaseType)
},
}

var dashboardTagSubCmd = &cobra.Command{
Use: "dashboard [ga,rc, alpha] [version]",
Short: "Tag dashboard releases",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("expected at least two arguments: [ga,rc] [version]")
}
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved

releaseType := args[0]

rc, err := releaseTypePreRelease(releaseType)
if err != nil {
return err
}

tag := args[1]
ctx := context.Background()
ghClient := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

dashboardRelease, found := rootConfig.Dashboard.Versions[tag]
if !found {
return errors.New("verify your config file, version not found: " + tag)
}

uiOpts := &repository.CreateReleaseOpts{
Tag: tag,
Repo: rootConfig.Dashboard.UIRepoName,
Owner: rootConfig.Dashboard.UIRepoOwner,
Branch: dashboardRelease.UIReleaseBranch,
}

if err := ui.CreateRelease(ctx, ghClient, &config.UIRelease{
PreviousTag: dashboardRelease.PreviousTag,
DryRun: dashboardRelease.DryRun,
}, uiOpts, rc, releaseType); err != nil {
return err
}

dashboardOpts := &repository.CreateReleaseOpts{
Tag: tag,
Repo: rootConfig.Dashboard.RepoName,
Owner: rootConfig.Dashboard.RepoOwner,
Branch: dashboardRelease.ReleaseBranch,
}

return dashboard.CreateRelease(ctx, ghClient, &dashboardRelease, dashboardOpts, rc, releaseType)
},
}

func init() {
rootCmd.AddCommand(tagCmd)

tagCmd.AddCommand(k3sTagSubCmd)
tagCmd.AddCommand(rke2TagSubCmd)
tagCmd.AddCommand(rancherTagSubCmd)
tagCmd.AddCommand(systemAgentInstallerK3sTagSubCmd)
tagCmd.AddCommand(uiTagSubCmd)
tagCmd.AddCommand(dashboardTagSubCmd)

// rke2
tagRKE2Flags.AlpineVersion = rke2TagSubCmd.Flags().StringP("alpine-version", "a", "", "Alpine version")
Expand Down
44 changes: 44 additions & 0 deletions cmd/release/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"errors"
"fmt"
"os"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/rancher/ecm-distro-tools/release/charts"
"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -130,11 +133,52 @@ var updateChartsCmd = &cobra.Command{
},
}

var updateRancherCmd = &cobra.Command{
Use: "rancher",
Short: "Update rancher files",
}

var updateRancherDashboardCmd = &cobra.Command{
Use: "dashboard [version]",
Short: "Update Rancher's Dashboard and UI references and create a PR",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("expected at least one argument: [version]")
}

version := args[0]
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved

// checking if the provided version is valid
_, err := semver.NewVersion(version)
if err != nil {
return err
}

versionTrimmed, _, _ := strings.Cut(version, "-rc")
briandowns marked this conversation as resolved.
Show resolved Hide resolved
versionTrimmed, _, _ = strings.Cut(versionTrimmed, "-alpha")

dashboardRelease, found := rootConfig.Dashboard.Versions[versionTrimmed]
if !found {
return errors.New("verify your config file, version not found: " + version)
}

dashboardRelease.Tag = version

ctx := context.Background()

ghClient := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

return rancher.UpdateDashboardReferences(ctx, rootConfig.Dashboard, ghClient, &dashboardRelease, rootConfig.User)
},
}

func init() {
rootCmd.AddCommand(updateCmd)
updateCmd.AddCommand(updateChartsCmd)
updateCmd.AddCommand(updateK3sCmd)
updateK3sCmd.AddCommand(updateK3sReferencesCmd)
updateCmd.AddCommand(updateRancherCmd)
updateRancherCmd.AddCommand(updateRancherDashboardCmd)
}

func validateChartConfig() error {
Expand Down
49 changes: 43 additions & 6 deletions cmd/release/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ type RancherRelease struct {
SkipStatusCheck bool `json:"skip_status_check"`
}

type UIRelease struct {
UIRepoOwner string `json:"ui_repo_owner" validate:"required"`
UIRepoName string `json:"ui_repo_name"`
PreviousTag string `json:"previous_tag"`
ReleaseBranch string `json:"release_branch" validate:"required"`
DryRun bool `json:"dry_run"`
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved
}

type DashboardRelease struct {
PreviousTag string `json:"previous_tag" validate:"required"`
ReleaseBranch string `json:"release_branch" validate:"required"`
UIReleaseBranch string `json:"ui_release_branch" validate:"required"`
UIPreviousTag string `json:"ui_previous_tag" validate:"required"`
Tag string
RancherReleaseBranch string `json:"rancher_release_branch" validate:"required"`
DryRun bool `json:"dry_run"`
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved
}

// RKE2
type RKE2 struct {
Versions []string `json:"versions"`
Expand Down Expand Up @@ -70,6 +88,23 @@ type Rancher struct {
Versions map[string]RancherRelease `json:"versions" validate:"dive,omitempty"`
}

// UI
type UI struct {
Versions map[string]UIRelease `json:"versions" validate:"dive"`
}

// Dashboard
type Dashboard struct {
Versions map[string]DashboardRelease `json:"versions" validate:"dive"`
RepoOwner string `json:"repo_owner" validate:"required"`
RepoName string `json:"repo_name" validate:"required"`
UIRepoOwner string `json:"ui_repo_owner" validate:"required"`
UIRepoName string `json:"ui_repo_name" validate:"required"`
RancherRepoOwner string `json:"rancher_repo_owner" validate:"required"`
RancherRepoName string `json:"rancher_repo_name" validate:"required"`
RancherUpstreamURL string `json:"rancher_upstream_url" validate:"required"`
}
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved

// Auth
type Auth struct {
GithubToken string `json:"github_token"`
Expand All @@ -82,12 +117,14 @@ type Auth struct {

// Config
type Config struct {
User *User `json:"user"`
K3s *K3s `json:"k3s" validate:"omitempty"`
Rancher *Rancher `json:"rancher" validate:"omitempty"`
RKE2 *RKE2 `json:"rke2" validate:"omitempty"`
Charts *ChartsRelease `json:"charts" validate:"omitempty"`
Auth *Auth `json:"auth"`
User *User `json:"user"`
K3s *K3s `json:"k3s" validate:"omitempty"`
Rancher *Rancher `json:"rancher" validate:"omitempty"`
RKE2 *RKE2 `json:"rke2" validate:"omitempty"`
Charts *ChartsRelease `json:"charts" validate:"omitempty"`
Auth *Auth `json:"auth"`
UI *UI `json:"ui"`
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved
Dashboard *Dashboard `json:"dashboard"`
}

// OpenOnEditor opens the given config file on the user's default text editor.
Expand Down
Loading
Loading